Good Afternoon,
I am trying to modify the following code to only search one sheet and not the whole workbook(remove the loop and check sheet2 only). I am not very savvy with VBA any help would be appreciated.
Public Sub FindTextFromCell()
'Run from standard module, like: Module1.
Sheet3.Cells.Clear
'Clear prevoius search result
Dim ws As Worksheet, Found As Range, rngNm As String
Dim myText As String, FirstAddress As String, thisLoc As String
Dim AddressStr As String, foundNum As Integer
myText = Sheets("Entry Form").Range("A10").Value
'Location of search box
If myText = "" Then Exit Sub
For Each ws In ThisWorkbook.Worksheets
With ws
Set Found = .UsedRange.Find(What:=myText, LookIn:=xlValues, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
If .Name = "Search Result" Then GoTo myNext
If .Name <> "Search Result" Then _
Found.EntireRow.Copy _
Destination:=Worksheets("Search Result").Range("A65536").End(xlUp).Offset(1, 0)
'The results go into the sheet listed above
Set Found = .UsedRange.FindNext(Found)
Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
End With
myNext:
Next ws
End Sub
I am trying to modify the following code to only search one sheet and not the whole workbook(remove the loop and check sheet2 only). I am not very savvy with VBA any help would be appreciated.
Public Sub FindTextFromCell()
'Run from standard module, like: Module1.
Sheet3.Cells.Clear
'Clear prevoius search result
Dim ws As Worksheet, Found As Range, rngNm As String
Dim myText As String, FirstAddress As String, thisLoc As String
Dim AddressStr As String, foundNum As Integer
myText = Sheets("Entry Form").Range("A10").Value
'Location of search box
If myText = "" Then Exit Sub
For Each ws In ThisWorkbook.Worksheets
With ws
Set Found = .UsedRange.Find(What:=myText, LookIn:=xlValues, MatchCase:=False)
If Not Found Is Nothing Then
FirstAddress = Found.Address
Do
If .Name = "Search Result" Then GoTo myNext
If .Name <> "Search Result" Then _
Found.EntireRow.Copy _
Destination:=Worksheets("Search Result").Range("A65536").End(xlUp).Offset(1, 0)
'The results go into the sheet listed above
Set Found = .UsedRange.FindNext(Found)
Loop While Not Found Is Nothing And Found.Address <> FirstAddress
End If
End With
myNext:
Next ws
End Sub