Want to MsgBox Results from VLookup

obb1uk

New Member
Joined
Mar 21, 2014
Messages
11
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
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,214,787
Messages
6,121,569
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top