Sub Vlookup_Values()
Dim a As Variant, b As Variant, c As Variant
Dim dic1 As Object, dic2 As Object
Dim i As Long, j As Long, k As Long, lr As Long, m As Long
Set dic1 = CreateObject("Scripting.Dictionary")
Set dic2 = CreateObject("Scripting.Dictionary")
a = Sheets("Sheet1").Range("A2", Sheets("Sheet1").Range("A" & Rows.Count).End(3)).Value2
With Sheets("Sheet2")
lr = .Range("A" & Rows.Count).End(3).Row
b = .Range("A2:B" & lr).Value2
m = Evaluate(Replace("=SUMPRODUCT((@<>"""")/COUNTIF(@,@&""""))", "@", .Name & "!B2:B" & lr)) 'unique
End With
ReDim c(1 To UBound(a), 1 To m)
For i = 1 To UBound(a)
dic1(a(i, 1)) = i & "|" & 1
Next
For i = 1 To UBound(b, 1)
If Not dic2.exists(b(i, 1) & "|" & b(i, 2)) Then
dic2(b(i, 1) & "|" & b(i, 2)) = b(i, 1)
If dic1.exists(b(i, 1)) Then
j = Split(dic1(b(i, 1)), "|")(0)
k = Split(dic1(b(i, 1)), "|")(1)
c(j, k) = b(i, 2)
k = k + 1
dic1(b(i, 1)) = j & "|" & k
End If
End If
Next
Sheets("Sheet1").Range("B2").Resize(UBound(c, 1), UBound(c, 2)).Value = c
End Sub