VBA-How to use "Find" property in all workbook

nader

Board Regular
Joined
Sep 26, 2005
Messages
135
I tried this code to find anyword in the workbook but it show result only for sheet active
PHP:
Cells.Find(What:="Anyword").Active

so I tried this code but didn't success. is there any help ?
PHP:
Dim wsh As Worksheet
For Each wsh In Workbook
wsh.Cells.Find(What:="Anyword").Activate
Next
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Perhaps try something like this. This will only find the first occurrence and then exit the procedure

Code:
Sub search()
Dim i, j As Integer

i = Worksheets.Count

For j = 1 To i
    Sheets(j).Activate
        If Cells.Find(What:="Text search") Is Nothing = False Then
            Exit Sub
        Else: MsgBox ("Not Found on Sheet " & j)
        End If
Next j

End Sub
 
Upvote 0
Your code don't work didn't find the word
this code work
PHP:
Dim wsh As Worksheet
Dim r As Range
For Each wsh In Worksheets
Set r = wsh.Cells.Find(what:="AnyWord")
If Not r Is Nothing Then
wsh.Activate
r.Activate
End If
Next wsh

Thank you for help!
 
Upvote 0
I'm not sure why exactly the code didn't work for you, it should work fine to find the first time your word shows up on the spreadsheet. However the code you posted will continue until it finds the last time it is mentioned. Perhaps there in lies the discrepancy.

Glad you've solved your problem.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,752
Members
452,940
Latest member
rootytrip

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top