Library code snippets

Adding a Find Button to an Excel Worksheet

The following code should be placed in the click procedure of your 'Find' Command Button (in this case it is called FindButton). When the button is pressed, the text that is present in a text box on your worksheet (in this case TextBox1) will be found. If the text does not exist on the worksheet, then an error message is displayed.

Private Sub FindButton_Click()
           Dim strFindWhat As String
           strFindWhat = TextBox1.Text
           On Error GoTo ErrorMessage

    Cells.Find(What:=strFindWhat, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False).Select
    Exit Sub
       ErrorMessage:
                  MsgBox ("The data you are searching for does not exist")
End Sub

Comments

  1. 21 Nov 2006 at 09:03
    Hey Man,
    Thanks for the code.
    Used it in VBA, works awesone with some minor tweaking
    Thanks a LOT !!!!! Big Smile [:D]




  2. 27 Dec 2002 at 23:03

    Help me!
    How contorl Excel in VB?
    thanks.
    help me!

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Adding a Find Button to an Excel Worksheet.

Leave a comment

Sign in or Join us (it's free).

 Gravitycure

Want to stay in touch with what's going on? Follow us on twitter!