Sub SearchExcel()
Dim strSearch As String
Dim rngFind As Range
Dim msg As Integer
Dim wb As Workbook, ws As Worksheet
' Get search string from the user
strSearch = InputBox("Enter search string: ", Title:="Find in Excel")
Application.ScreenUpdating = False
For Each wb In Excel.Workbooks
For Each ws In wb.Worksheets
With ws.UsedRange
' Search for the string
On Error Resume Next
Set rngFind = .Find(What:=strSearch, After:=Range("A1"), _
LookIn:=xlValues, LookAt:=xlWhole, SearchDirection:=xlNext)
If Not rngFind Is Nothing Then
firstFind = rngFind.Address
Do
' Alert user if search string found & query if search should continue
msg = MsgBox("Search string found!" & Chr(13) & Chr(13) & _
"Cell: " & rngFind.Address(False, False) & Chr(13) & _
"Worksheet: " & rngFind.Worksheet.Name & Chr(13) & _
"Workbook: " & rngFind.Worksheet.Parent.Name & Chr(13) & Chr(13) & _
"Would you like to continue searching?", vbYesNo)
If msg = vbYes Then
Set rngFind = .FindNext(rngFind)
Else
' Select the cell if query ended
With rngFind
.Worksheet.Parent.Activate
.Worksheet.Activate
.Select
GoTo EndSub:
End With
End If
Loop While rngFind.Address <> firstFind
End If
On Error GoTo 0
End With
Next ws
Next wb
EndSub:
Application.ScreenUpdating = True
Set rngFind = Nothing
Set ws = Nothing
Set wb = Nothing
End Sub
' If no range has been selected, check to select last range
msg = MsgBox("No additional matches found. " & _
"Would you like to go to the final match?", vbYesNo)
If msg = vbYes Then
With rngFind
.Worksheet.Parent.Activate
.Select
End With
End If
Hi Ben,
I've tested again. This time with 1 open workbook
I have text in cell A1 of sheet 1 and the same text in cell C4 of sheet2.
My Code is in module1.
When I run the macro it finds the text in cell A1 of sheet1, but then when I click yes to find the second instance the message box pops up again but still displays 'found in cell A1 of sheet1'. On clicking yes again the macro ends. It doesn't seem to find the sheet2 instance in cell C4????
I am stumped!!!
Fax.
But the 'within' field is toggled to 'sheet'. Should this be toggled to 'workbook'??