ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Find in VBA (https://www.excelbanter.com/excel-programming/396180-using-find-vba.html)

nir020

Using Find in VBA
 
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?

Vergel Adriano

Using Find in VBA
 
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


--
Hope that helps.

Vergel Adriano


"nir020" wrote:

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?


Tom Ogilvy

Using Find in VBA
 
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

--
Rgards,
Tom Ogilvy

"nir020" wrote:

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?



All times are GMT +1. The time now is 03:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com