Help with a Macro that searches over multiple sheets.

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:

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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top