Using Find in VBA

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have written the following VBA which is used to find the text "ERROR"
within a worksheet:-

Cells.Find(What:="ERROR", After:= _
ActiveCell, LookIn:=xlValues).Activate

I would like to extend this Sub routine so that it search through the entire
workbook and if the text "ERROR" is found a message box is activated and the
sub broken.

Can anyone help?
 
maybe something like this:

Sub test()
Dim sht As Worksheet
Dim c As Range

For Each sht In Worksheets
Set c = sht.Cells.Find(What:="ERROR")
If Not c Is Nothing Then
sht.Activate
c.Activate
MsgBox "ERROR FOUND!"
Exit Sub
End If
Next sht
MsgBox "NO ERRORS FOUND"

End Sub
 
Dim sh as worksheet, rng as range
for each sh in worksheets
sh.Activate
set rng = Cells.Find(What:="ERROR", After:= _
ActiveCell, LookIn:=xlValues)
if not rng is nothing then
msgbox "Error found at " & rng.Address(0,0,xlA1,True)
exit sub
end if
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top