I'm having a hard time getting a custom vlookup formula to work.
I need to be able to change a part of the range in the vlookup dynamically based on a cell value.
This is what I came up with but it gives me a value error. Can anyone help?
Function VL(val As Variant, RNG As Range, col As Integer, BL As Boolean)
Dim Lookup As Range
Set Lookup = Range("'C:\AirlineData\Total O&D\[" & RNG & " Total O&D.xls]by market'!$B$1:$D$65536")
VL = WorksheetFunction.VLookup(val, Lookup, col, BL)
End Function
I need to be able to change a part of the range in the vlookup dynamically based on a cell value.
This is what I came up with but it gives me a value error. Can anyone help?
Function VL(val As Variant, RNG As Range, col As Integer, BL As Boolean)
Dim Lookup As Range
Set Lookup = Range("'C:\AirlineData\Total O&D\[" & RNG & " Total O&D.xls]by market'!$B$1:$D$65536")
VL = WorksheetFunction.VLookup(val, Lookup, col, BL)
End Function