I have a userform textbox and I want to search all worksheets for the value in the textbox and display the results in a listbox, there could be multiple results.
Information.
Userform1
Textbox1 (search text entered)
Listbox1 (shows results of worksheet name where found + cell text where found + cell address where found)
Msgbox show the count of the number of times that the text was found and also each cell where it was found with a line space between each result.
I tried the following but it didn't work.
Information.
Userform1
Textbox1 (search text entered)
Listbox1 (shows results of worksheet name where found + cell text where found + cell address where found)
Msgbox show the count of the number of times that the text was found and also each cell where it was found with a line space between each result.
I tried the following but it didn't work.
VBA Code:
ListBox1.Clear
Dim ws As Worksheet, Found As Range
Dim myText As String, FirstAddress As String, List1 As String
Dim AddressStr As String, foundNum As Integer
myText = Me.Textbox1
For Each ws In ThisWorkbook.Worksheets
With ws
Set Found = .UsedRange.Find(what:=myText, LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
foundNum = foundNum + 1
AddressStr = AddressStr & "in Sheet: " & .Name & " " & "Cell address: -- " & Found.Address & vbCrLf
Set Found = .UsedRange.FindNext(Found)
ListBox1.AddItem AddressStr
Loop While Not Found Is Nothing And Found.Address <> FirstAddress
myNext:
End If
End With
Next ws
If Len(AddressStr) Then
MsgBox "Found :""" & myText & """ " & foundNum & " times." & vbLf & AddressStr, vbOKOnly, myText & " found in these cells"
Else:
MsgBox "Unable to find " & myText & " in this workbook.", vbExclamation
End If