I have 2 Worksheets, the first one with 40k+ (Sheet1S) entries which I have to vlookup in the second sheet (Sheet2S), which has 300k+ entries.
I have written this script to run a vlookup based on scripting dictonary which works if i adjust the for loop to 10 rows (I uncommented the actual for loop). However, it takes ages if I use all the rows:
Sub aTest()
Dim a As Variant, i As Long
With CreateObject("Scripting.Dictionary")
a = Sheets("Sheet2S").Range("A1").CurrentRegion.Value
For i = 2 To 10
'For i = 2 To UBound(a, 1)
.Item(a(i, 1)) = Application.Index(a, i, 0)
Next
a = Sheets("Sheet1S").Range("A1").CurrentRegion.Value
'For i = 2 To UBound(a, 1)
For i = 2 To 10
If .exists(a(i, 1)) Then
a(i, 2) = .Item(a(i, 1))(2)
'a(i, 4) = .Item(a(i, 2))(3)
Else
a(i, 2) = "#N/A"
End If
Next i
End With
Sheets("Sheet1S").Range("a1").CurrentRegion.Value = a
End Sub
Now according to an old thread (How to optimize vlookup for high search count ? (alternatives to VLOOKUP)) the dictionary method should only be a few seconds. If I use Application.Vlookup it takes me up to 10min for the exact same sheets which is too long for me. I am using Excel 2016 and I've added the the Microsoft Scripting Runtime. Am I doing something wrong?
Thanks in advance.
Best