• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to find a string in the entire workbook

ThrottleWorks

Excel Ninja
Hi,
I want to find a string in the entire workbook. Following code helps finding only in one sheet.

The string might be present in any sheet, so I have to search the entire workbook.
For example, I have 20 sheets in a book but I am not sure in which sheet the string is present. So need to search till I get result.

Can anyone please help me in this.

Code:
On Error Resume Next
                Cells.Find(What:=Class, After:=ActiveCell, LookIn:= _
                xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
                xlNext, MatchCase:=False, SearchFormat:=False).Activate
On Error GoTo 0
 
Hi Sachin ,

You can put the posted code within a For ... Next loop as in :

Code:
Public Sub Find_text()
           searchtext = "Tentacle"                 ' Change as required
           For Each ws In Worksheets
               ws.Activate
               Set found = ws.Cells.Find(What:=searchtext, After:=ActiveCell, LookIn:= _
                xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _
                xlNext, MatchCase:=False, SearchFormat:=False)
               If Not (found Is Nothing) Then
                  found.Select
                  Exit For
               End If
           Next
End Sub
Narayan
 
Back
Top