Hi.
I'm trying to lookup each value of table1 in table2 giving the second column. In table2 data is sorted.
TABLE1...
TABLE2..
I TRIED TO USE FINDNEXT TO GIVE ME THE SECOND COL IN THE RESULT BUT IT IS NOT WORKING AND TAKES A LOT OF TIME.
I'm trying to lookup each value of table1 in table2 giving the second column. In table2 data is sorted.
TABLE1...
LOOKUP VALUE | RESULT |
A | A1 |
A | A2 |
A | A3 |
A | A4 |
B | B1 |
B | B2 |
B | B3 |
C | C1 |
B | B1 |
B | B2 |
B | B3 |
TABLE2..
COL1 | COL2 |
A | A1 |
A | A2 |
A | A3 |
A | A4 |
B | B1 |
B | B2 |
B | B3 |
C | C1 |
I TRIED TO USE FINDNEXT TO GIVE ME THE SECOND COL IN THE RESULT BUT IT IS NOT WORKING AND TAKES A LOT OF TIME.
Code:
Dim ws As Worksheet
Dim LRB As Long
Dim cell As Range
Dim Orng As Range
Dim iCounter As Integer
Dim LOOKUPRng As String
Set ws = Sheets("BOM")
LRB = Sheets("bom").Cells(Rows.Count, "F").End(xlUp).Row
With Range("Table5[out]")
LOOKUPRng = .Find(ComboBox2.Value, , xlValues).Offset(0, 9).Value & "[LOOKUP VALUE]"
End With
For Each cell In ws.Range("A2:A" & LRB)
With Range(LOOKUPRng)
Set Orng = .Find(cell.Value, , xlValues)
iCounter = 2
Do
If Not Orng Is Nothing Then
ws.Cells(iCounter, 2).Value = Orng.Offset(0, 1).Value
Set Orng = .FindNext(Orng)
End If
Loop While iCounter <= LRB
End With
Next