I am trying to run VLookup to display the result in variable called Tax.
Looking up examples, I cannot somehow get my code to do what I want.
I also want to preset the searchkey in a variable called eno
I have commented the code to show "code working" or "code not working"
Please help, see code below:
Sub FINDTAX()
' macro to do a Vlookup and display the result in variable Tax, using eno as input
Dim eno As Long
eno = 43
dsname = "D:\Data\LRV\2018 Calendar.xlsm"
' ActiveCell.FormulaR1C1 = "=IFNA(VLOOKUP(RC[1],'" + dsname + "'!TaxWk,3,FALSE),"""")" ' code working ok
' the above line puts =IFNA(VLOOKUP(F8,'D:\Data\lrv\2018 Calendar.xlsm'!TaxWk,3,FALSE),"") in Column E
ActiveCell.FormulaR1C1 = "=IFNA(VLOOKUP(eno,'" + dsname + "'!TaxWk,3,FALSE),"""")" ' code not working
' Tax = Application.WorksheetFunction.VLookup(eno, '" + dsname + "'!TaxWk, 3, False) ' code not working
MsgBox "Tax Info is : " & Tax
End Sub
Looking up examples, I cannot somehow get my code to do what I want.
I also want to preset the searchkey in a variable called eno
I have commented the code to show "code working" or "code not working"
Please help, see code below:
Sub FINDTAX()
' macro to do a Vlookup and display the result in variable Tax, using eno as input
Dim eno As Long
eno = 43
dsname = "D:\Data\LRV\2018 Calendar.xlsm"
' ActiveCell.FormulaR1C1 = "=IFNA(VLOOKUP(RC[1],'" + dsname + "'!TaxWk,3,FALSE),"""")" ' code working ok
' the above line puts =IFNA(VLOOKUP(F8,'D:\Data\lrv\2018 Calendar.xlsm'!TaxWk,3,FALSE),"") in Column E
ActiveCell.FormulaR1C1 = "=IFNA(VLOOKUP(eno,'" + dsname + "'!TaxWk,3,FALSE),"""")" ' code not working
' Tax = Application.WorksheetFunction.VLookup(eno, '" + dsname + "'!TaxWk, 3, False) ' code not working
MsgBox "Tax Info is : " & Tax
End Sub