Macro to find a value in a worksheet

Closed
azmiismail Posts 17 Registration date Thursday 3 March 2011 Status Member Last seen 20 July 2011 - 9 Mar 2011 à 22:51
rizvisa1 Posts 4478 Registration date Thursday 28 January 2010 Status Contributor Last seen 5 May 2022 - 10 Mar 2011 à 05:29
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 28 January 2010 Status Contributor Last seen 5 May 2022 766
10 Mar 2011 à 05:29
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