.Find to look through numerous sheets

XcelNoobster

New Member
Joined
Jun 7, 2022
Messages
40
I need some help with using the .find to search through numerous sheets.

I have a sheet with Ids that I want to loop through each one and search each sheet for that value's location then output the location on a new sheet called "Results"

This is what I have so far but getting an error and not sure if my logic is correct.

VBA Code:
Sub findIds()

Dim I As Long, temp As String
Dim A As Integer
Dim firstAddress As String
Dim sht As Worksheet
Dim c As Range

For I = 1 To Range("A" & Rows.Count).End(xlUp).Row
    temp = Cells(I, "A").Value
    For Each sht In ThisWorkbook.Sheets
        Set c = .Find(temp, LookIn:=xlValues)
        If Not x Is Nothing Then
            firstAddress = c.Address
            Do
            Sheets("Results").Range("D" & I) = firstAddress
        End If
    Next sht
Next I

End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi Noobster,

almost there I think .. well done.

I tried this (amended slightly from yours). I think ok providing the value you want is only on the sheet once - else another loop of some kind will need to be looked at.
You also had a Do statement which was missing a Loop, but isn't necessary here anyway so I removed it.

VBA Code:
Sub findIds()

Dim I As Long, temp As String
Dim A As Integer
Dim firstAddress As String
Dim sht As Worksheet
Dim c As Range

For I = 1 To Range("A" & Rows.Count).End(xlUp).Row
    temp = Cells(I, "A").Value
    For Each sht In ActiveWorkbook.Sheets
    
        With sht.Cells
        
          Set Rng = .Find(What:=temp, After:=ActiveCell, LookIn:=xlFormulas, _
             LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
             MatchCase:=False, SearchFormat:=False)
        
            If Not Rng Is Nothing Then
                firstAddress = Rng.Address
                Sheets("Results").Range("D" & I) = firstAddress
            End If
        End With
    Next sht
Next I

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,952
Members
449,095
Latest member
nmaske

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