'' ***************************************************************************
'' Purpose : Lookup function based on two columns / Demonstrate use of Evaluate
'' Written : 30-Oct-2001 by Andy Wiggins, Byg Software Limited
'' Amended : 09-May-2002 by Andy Wiggins
''
Function VLOOKUP2(pVal1, pVal2, pRng As Range, pInd As Integer)
''The lookup values refer to columns 1 and 2 in the range
Application.Volatile
Dim lStr_Seek As String
Dim lStr_Col1 As String
Dim lStr_Col2 As String
Dim lStr_Col3 As String
''If an error occurs with "Evaluate" it isn't passed to this function's error handler
''This handler will pick up any other errors that may occur
On Error GoTo Error_VLOOKUP2
''The quotes enure strings are treated as such and NOT as range names
lStr_Seek = """" & pVal1 & ":""&""" & pVal2 & """"
lStr_Col1 = pRng.Columns(1).Address
lStr_Col2 = pRng.Columns(2).Address
lStr_Col3 = pRng.Columns(pInd).Address
VLOOKUP2 = Evaluate("index(" & lStr_Col3 & ",match(" & _
lStr_Seek & "," & lStr_Col1 & "&"":""&" & lStr_Col2 & ",0))")
Exit Function
Error_VLOOKUP2:
VLOOKUP2 = Err
End Function
|