Option Explicit
Sub test()
Dim a, i As Long
a = Sheets("Lookup").Cells(1).CurrentRegion.Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 2 To UBound(a, 1)
If Not .exists(a(i, 1)) Then
Set .Item(a(i, 1)) = _
CreateObject("Scripting.Dictionary")
.Item(a(i, 1)).CompareMode = 1
End If
If a(i, 2) = "donot_care" Then a(i, 2) = "*"
If a(i, 3) Like "anything*" Then
a(i, 3) = "<>" & Split(a(i, 3))(2)
ElseIf a(i, 3) = "donot_care" Then
a(i, 3) = "*"
Else
a(i, 3) = "=" & a(i, 3)
End If
.Item(a(i, 1))(a(i, 2)) = VBA.Array(a(i, 3), a(i, 4))
Next
a = Sheets("sample_data").Cells(1).CurrentRegion.Value
For i = 2 To UBound(a, 1)
a(i, UBound(a, 2)) = Empty
If .exists(a(i, 1)) Then
If .Item(a(i, 1)).exists(a(i, 2)) Then
If Evaluate(a(i, 3) & .Item(a(i, 1))(a(i, 2))(0)) Then
a(i, UBound(a, 2)) = .Item(a(i, 1))(a(i, 2))(1)
Else
If .Item(a(i, 1)).exists("*") Then
If Evaluate(a(i, 3) & .Item(a(i, 1))("*")(0)) Then
a(i, UBound(a, 2)) = .Item(a(i, 1))("*")(1)
End If
End If
End If
Else
If .Item(a(i, 1)).exists("*") Then
a(i, UBound(a, 2)) = .Item(a(i, 1))("*")(1)
End If
End If
End If
Next
End With
Sheets("sample_data").Cells(1).CurrentRegion.Value = a
End Sub
Bookmarks