In this particular answer regarding faster way of vlookup - https://stackoverflow.com/a/18656809/8036266
A faster way of vlookup is mentioned, defined as vbalookup. The code for this is working perfectly fine. However, it is executing everytime I change any cell in the workbook. Can somebody please tell me what the issue could be?
Function vbalookup(lookupRange As Range, refRange As Range, dataCol As Long)
As Variant
Dim dict As New Scripting.Dictionary
Dim myRow As Range
Dim I As Long, J As Long
Dim vResults() As Variant
' 1. Build a dictionnary
For Each myRow In refRange.Columns(1).Cells
' Append A : B to dictionnary
dict.Add myRow.Value, myRow.Offset(0, dataCol - 1).Value
Next myRow
' 2. Use it over all lookup data
ReDim vResults(1 To lookupRange.Rows.Count, 1 To lookupRange.Columns.Count)
As Variant
For I = 1 To lookupRange.Rows.Count
For J = 1 To lookupRange.Columns.Count
If dict.Exists(lookupRange.Cells(I, J).Value) Then
vResults(I, J) = dict(lookupRange.Cells(I, J).Value)
End If
Next J
Next I
vbalookup = vResults
End Function