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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,223,991
Messages
6,175,820
Members
452,672
Latest member
missbanana

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