XcelNoobster
New Member
- Joined
- Jun 7, 2022
- Messages
- 40
So I have a sheet called "IDs" that has a list of Ids and a sheet called "Results". I want to look through each Id, search all the sheets and print all the location where each ID is found in "Results" print them on seperate cells.
So currently right now, my macro is printing only the last location where the Id is found in one cell instead of printing each location on a different cells.
So currently right now, my macro is printing only the last location where the Id is found in one cell instead of printing each location on a different cells.
VBA Code:
Sub findIds()
Dim i As Long, temp As String
Dim output_row As Long
Dim A As Integer
Dim firstAddress As String
Dim sht As Worksheet
Dim c As Range
output_row = 1
For i = 1 To Range("A" & Rows.Count).End(xlUp).Row
temp = Cells(i, "A").Value
For Each sht In ActiveWorkbook.Sheets
If sht.Name = "IDs" Then
'Do Nothing
Else
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 + ": " & sht.Name + ": "
output_row = output_row + 1
End If
End With
End If
Next sht
Next i
End Sub