View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Search all sheets

Sub FindAll()
Dim sh As Worksheet
Dim rng As Range, firstAddress as String
For Each sh In ThisWorkbook.Worksheets
Set rng = sh.Cells.Find(What:="1", After:=ActiveCell, LookIn:=xlFormulas,
_
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False)
If Not rng Is Nothing Then
firstaddress = rng.Address
Do
If Not rng Is Nothing Then
Application.Goto rng, True
MsgBox "Hit key to continue"
End If
Set rng = sh.Cells.FindNext(rng)
Loop Until rng.Address = firstaddress
End If
Next
End Sub

--
Regards,
Tom Ogilvy


"Steve Wylie" wrote in message
...
I need a short macro that will search all sheets in the
active workbook for a certain string of text, and when it
finds it, it stops at that point on that sheet.

I asked a question of this newsgroup some time ago about
doing a Find & Replace operation across multiple sheets,
and got a reply, but I cannot figure out how to amend the
macro to just find and not find and replace. Could
anyone suggest how I could alter the macro below just to
do a Find on multiple sheets?

Thanks, Steve


The following macro will loop through all of the sheets
in the workbook and remove every occurrence of 1, and
replace it with 2, just for example.


The On Error Resume Next line prevents the error
developed when the last sheet is encountered and
the .Next.Select line tries to execute, which it can not,
since it is at the last sheet already.