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