Cell Search


Posted by Rob on April 27, 2001 12:06 AM

Is there a bit of VB code or something else that makes excel's "Find" look in all the worksheets in the workbook? Currently, the search only works for the selected sheet.
Thanks

Posted by Ivan Moala on April 27, 2001 12:11 AM

Here's a piece of code by Jan Karel Pieterse
Give credit to Jan
Ivan

'This procedure searches through all worksheets in a workbook.

Sub FindItAll()
Dim oSheet As Object
Dim Firstcell As Range
Dim NextCell As Range
Dim WhatToFind As Variant
WhatToFind = Application.InputBox("What are you looking for ?", "Search", , 100, 100, , , 2)
If WhatToFind <> "" And Not WhatToFind = False Then
For Each oSheet In ActiveWorkbook.Worksheets
oSheet.Activate
oSheet.[a1].Activate
Set Firstcell = Cells.Find(What:=WhatToFind, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
If Not Firstcell Is Nothing Then
Firstcell.Activate
MsgBox ("Found " & Chr(34) & WhatToFind & Chr(34) & " in " & oSheet.Name & "!" & Firstcell.Address)
On Error Resume Next
While (Not NextCell Is Nothing) And (Not NextCell.Address = Firstcell.Address)
Set NextCell = Cells.FindNext(After:=ActiveCell)
If Not NextCell.Address = Firstcell.Address Then
NextCell.Activate
MsgBox ("Found " & Chr(34) & WhatToFind & Chr(34) & " in " & oSheet.Name & "!" & NextCell.Address)
End If
Wend
End If
Set NextCell = Nothing
Set Firstcell = Nothing
Next oSheet
End If
End Sub



Posted by Dave Hawley on April 27, 2001 1:35 AM

Hi Rob

If you right click on any sheet name tab and select "Select all sheet" then use the standard Edit>Find/Replace it will search all sheets


Dave

OzGrid Business Applications