In Excel, you can have multiple criteria when using the Xlookup feature.
A "normal" Xlookup looks something like this:
=xlookup("ThingToLookFor", "Search Range", "Return Range")
A multiple criteria Xlookup looks something like this:
=xlookup("ThingToLookFor" & "OtherThingToLookFor", "Search Range 1" & "Search Range 2", "Return Range")
I'm trying to do a multiple criteria Xlookup in VBA. Using & combines the two strings together, so that's no good.
What is the correct version of this in VBA?
WorksheetFunction.Xlookup("ThingToLookFor" & OtherThingToLookFor", "Search Range 1" & "Search Range 2", "Return Range")?
Note: I did discover "Evaluate". I can make it work, but I'm not sure I like it.
A more specific example:
Sub xlookup_test()
Dim Lookup_Value_1 As String
Lookup_Value_1 = "My Document"
Dim Lookup_Value_2 As String
Lookup_Value_2 = "Sales"
Dim Search_List_1 As Range
Set Search_List_1 = Document_Control.Range("DC_Document_Type")
Dim Search_List_2 As Range
Set Search_List_2 = Document_Control.Range("DC_Document_Name")
Dim Return_List As Range
Set Return_List = Document_Control.Range("DC_Document_ID")
Dim Return_Value As String
' this is the problem line
Return_Value = WorksheetFunction.XLookup(Lookup_Value_1 & Lookup_Value_2, Search_List_1 & Search_List_2, Return_List)
Debug.Print (Return_Value)
End Sub
However, as mentioned before, using the & is just combining the two strings together to make one string instead of telling it that it's two different things it needs to look for.