Macro to find a value in a worksheet

Closed
azmiismail Posts 17 Registration date Thursday March 3, 2011 Status Member Last seen July 20, 2011 - Mar 9, 2011 at 10:51 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Mar 10, 2011 at 05:29 AM
Hello,

I am new with excel macro and VBA codes.Can someone out there help me with the macro and VBA code to create an input boxes to seacrh and find a value in a list of a worksheet.

worksheet name:(Sheet2)B2JT
Range to seach :A9:AA39

Thanks.

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Mar 10, 2011 at 05:29 AM
If you are new to macro, a very good starting point would be using macro recorder. It can give a general template for what you need.

Here is a macro that can do what you wanted

Sub doExecuteSearch()

   Dim sSearchFor          As String
   Dim rngCell             As Range
   
   Do
      
      sSearchFor = InputBox("Please enter value to be searched", "Search")
      If sSearchFor <> vbNullString _
      Then
         With Sheets("B2JT")
            Set rngCell = .Range("a2:a9").Find(sSearchFor, .Cells(8, 1), , xlWhole, xlByRows, xlNext)
            If Not rngCell Is Nothing _
            Then
               MsgBox "found at row " & rngCell.Row & " and column " & rngCell.Column
            Else
               MsgBox "Not found"
            End If
         End With
      End If
   
   Loop While sSearchFor <> vbNullString
   
End Sub
0