StrapsTivis
New Member
- Joined
- Oct 3, 2013
- Messages
- 14
This is in reference to the following thread:
http://www.mrexcel.com/forum/excel-...applications-search-over-multiple-sheets.html
I'm trying to accomplish the same thing. I have multiple sheets that users may want to search all of, and then have the results dumped into a sheet labeled Results.
I used the Code that was posted in that thread, which I will include below. The issue I'm having, is that when it's done running.. I only get 1 row of returned results.. and I know there should be more than just ONE result. Is there something I'm overlooking or something I copied over wrong?
Here is the code:
http://www.mrexcel.com/forum/excel-...applications-search-over-multiple-sheets.html
I'm trying to accomplish the same thing. I have multiple sheets that users may want to search all of, and then have the results dumped into a sheet labeled Results.
I used the Code that was posted in that thread, which I will include below. The issue I'm having, is that when it's done running.. I only get 1 row of returned results.. and I know there should be more than just ONE result. Is there something I'm overlooking or something I copied over wrong?
Here is the code:
Code:
Public Sub FindText()
'Run from standard module, like: Module1.
'Find all data on all sheets!
'Do not search the sheet the found data is copied to!
'List a message box with all the found data addresses, as well!
Dim ws As Worksheet, Found As Range
Dim myText As String, firstAddress As String
Dim AddressStr As String, foundNum As Integer
myText = InputBox("Enter text to find")
If myText = "" Then Exit Sub
For Each ws In ThisWorkbook.Worksheets
With ws
'Do not search sheet4!
If ws.Name = "Results" Then GoTo myNext
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 & .Name & " " & Found.Address & vbCrLf
Set Found = .UsedRange.FindNext(Found)
'Copy found data row to Results Option!
Found.EntireRow.Copy _
Destination:=Worksheets("Results").Range("A65536").End(xlUp).Offset(1, 0)
Loop While Not Found Is Nothing And Found.Address <> firstAddress
End If
myNext:
End With
Next ws
'If Len(AddressStr) Then
'MsgBox "Found: """ & myText & """ " & foundNum & " times." & vbCr & _
'AddressStr, vbOKOnly, myText & " found in these cells"
'Else:
'MsgBox "Unable to find " & myText & " in this workbook.", vbExclamation
'End If
End Sub