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

You might also like...

Comments

 gravitycure

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.” - Jamie Zawinski