.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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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