polarisking
Member
The macro works when
- the LU .xlsx workbook is open, and
- is in the same directory as the macro, and
- I DON'T qualify the lookup workbook with a path
- the LU .xlsx workbook is open, and
- IS NOT in the same directory as the macro, and
- I DO qualify (I have to, right?) the lookup workbook with a path
- The failure is "Subscript out of Range"
Code:
Sub VLUtest()
Dim Range_Lookup As Range
Dim LU_Value As Variant
Dim found_value As Variant
LU_Value = 3
'Set Range_Lookup = Workbooks("TestVBALU-LookupTable.xlsx").Worksheets("sheet1").Range(("a1:b4") 'works
Set Range_Lookup = Workbooks("C:\Users\PatandDonna\Desktop\TestVBALU-LookupTable.xlsx").Worksheets("sheet1").Range("a1:b4")
found_value = Application.VLookup(LU_Value, Range_Lookup, 2, False)
Debug.Print found_value
If IsError(found_value) Then
'n/a would have been returned
Else
'no error
End If
End Sub