S
scott
I'm trying to search all cells ONLY within the active worksheet and find
every instance of a string. My FindString sub below searches all worksheets
and it only finds the 1st instance of the string before moving to another
worksheet.
Can someone help me modify my code to search for ALL instances of a string
and limit the search to just the active worksheet?
' CODE:
Sub FindString(sString As String)
Dim bk As Workbook, sh As Worksheet
Dim rng As Range, ans As Long
For Each bk In Application.Workbooks
For Each sh In bk.Worksheets
Set rng = sh.Cells.Find(sString)
If Not rng Is Nothing Then
Dim sMsg, iStyle, sTitle, Help, Ctxt, Response
sMsg = "Found at " & rng.Address(external:=True) & vbCrLf &
vbCrLf & _
"Do you want to continue ?"
iStyle = vbYesNo + vbInformation + vbDefaultButton2
sTitle = "Find String"
Response = MsgBox(sMsg, iStyle, sTitle)
If Response = vbYes Then
'Continue to search
ElseIf Response = vbNo Then
Exit Sub
End If
End If
Next
Next
End Sub
every instance of a string. My FindString sub below searches all worksheets
and it only finds the 1st instance of the string before moving to another
worksheet.
Can someone help me modify my code to search for ALL instances of a string
and limit the search to just the active worksheet?
' CODE:
Sub FindString(sString As String)
Dim bk As Workbook, sh As Worksheet
Dim rng As Range, ans As Long
For Each bk In Application.Workbooks
For Each sh In bk.Worksheets
Set rng = sh.Cells.Find(sString)
If Not rng Is Nothing Then
Dim sMsg, iStyle, sTitle, Help, Ctxt, Response
sMsg = "Found at " & rng.Address(external:=True) & vbCrLf &
vbCrLf & _
"Do you want to continue ?"
iStyle = vbYesNo + vbInformation + vbDefaultButton2
sTitle = "Find String"
Response = MsgBox(sMsg, iStyle, sTitle)
If Response = vbYes Then
'Continue to search
ElseIf Response = vbNo Then
Exit Sub
End If
End If
Next
Next
End Sub