Hello guys!
I am an excel VBA newbie and I have created an excel workbook that I use to store meeting minutes. As part of the application I have a userform from which I can search any previously saved data. below is a snippet of the code I am using:
Dim d As Range
With Worksheets("Bank").Range("C2 : C10000")
Set c = .Find(SearchTextBox.Text, LookIn:=xlValues)
Set k = Worksheets("Bank").Columns("C").Find(what:=SearchTextBox.Text, LookIn:=xlValues, lookat:=xlWhole)
If Not c Is Nothing Then
On Error GoTo ErrMsg
DisplayUserform.TextBoxResults1.Text = Sheets("Bank").Range("A" & k.Row)
DisplayUserform.TextBoxResults2.Text = Sheets("Bank").Range("B" & k.Row)
DisplayUserform.TextBoxResults3.Text = Sheets("Bank").Range("C" & k.Row)
DisplayUserform.Show
Worksheets("Bank").Activate
Range("A" & k.Row).Activate
Worksheets("Default").Activate
End If
If c Is Nothing Then
On Error GoTo ErrMsg
DisplayUserform.Show
DisplayUserform.TextBoxResults1.Text = "---"
DisplayUserform.TextBoxResults2.Text = "---"
DisplayUserform.TextBoxResults3.Text = "Sorry, your search did not return any results."
Worksheets("Default").Activate
End If
End With
Exit Sub
The problem is that with this code I can only return results if the search query exactly matches the saved data. How do I search and return results if the search query is part of the saved data? For example I would like a situation where the saved data is "I love code" and if I search for "code" or just "I love" I will still be able to return results.
May someone please help me as soon as you can.
Thanks vey much code gurus!!!
Bookmarks