I found a thread for a loop function that works like vlookup (thank you for the code, MickG). This code finds every match in the lookup range, but I only want it to find the first match and then loop to the next value to look up. Here is the code:
Dim oDat As Range, Rng As Range, Ocl As Range, Cl As Range
Dim Found As Boolean
Set oDat = Sheets("Data").Range(Sheets("Data").Range("A2"), Sheets("Data").Range("A" & Rows.Count).End(xlUp))
Set Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
For Each Cl In Rng
Found = False
For Each Ocl In oDat
If Cl.Value = Ocl.Value Then
Cl.Offset(, 2).Value = Ocl.Offset(, 1).Value
Found = True
End If
Next Ocl
If Found = False Then
Cl.Offset(, 2).Value = 0
End If
Next Cl
End Sub
When the value from the first cell in Rng is found in the oDat range, I want it to execute the code on that cell in the oDat range and then loop back to the second cell in Rng and execute the code on the first value it finds in the oDat range, etc. This code finds every match from the first cell in Rng in the oDat range and executes the code on every match.
Thank you in advance for your help.
Bookmarks