I am currently using a macro to search all sheets within an Excel file. The limitation I was hoping to overcome is the fact that the search only returns results if the words are in consecutive order ie red white blue will only match to red white blue in that order and not return results of white blue red. Kind of how Google will let you search without being 100% accurate on the order of words.
Is there any way around this? Very many thanks for any help!
Using Excel 2003 with the following code:
Sub Locate(Name As String, Data As Range)
Dim rngFind As Range
Dim strFirstFind As String
With Data
Set rngFind = .Find(Name, LookIn:=xlValues, lookat:=xlPart)
If Not rngFind Is Nothing Then
strFirstFind = rngFind.Address
Do
If rngFind.Row > 1 Then
ListBox1.AddItem rngFind.Value
ListBox1.List(ListBox1.ListCount - 1, 1) = Data.Parent.Name
ListBox1.List(ListBox1.ListCount - 1, 2) = Data.Parent.Name & "!" & rngFind.Address
End If
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> strFirstFind
End If
End With
End Sub
Private Sub CommandButton1_Click()
Dim shtSearch As Worksheet
ListBox1.Clear
For Each shtSearch In ThisWorkbook.Worksheets
Locate TextBox1.Text, shtSearch.Range("A:F")
Next
If ListBox1.ListCount = 0 Then
ListBox1.AddItem "No Match Found"
ListBox1.List(0, 1) = ""
ListBox1.List(0, 2) = ""
End If
End Sub
Private Sub Label1_Click()
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim strSheet As String
Dim strAddress As String
strSheet = ListBox1.List(ListBox1.ListIndex, 1)
strAddress = ListBox1.List(ListBox1.ListIndex, 2)
If strAddress <> "" Then
Worksheets(strSheet).Activate
Range(strAddress).Activate
End If
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub UserForm_Click()
End Sub
Bookmarks