VBA Assign Vlookup Result To Variable

Lewzerrrr

Active Member
Joined
Jan 18, 2017
Messages
256
Hey,

I’ve searched around for this, what I’m trying to do is store a vlookup result inside my variable. At first I switched my sheet to R1C1 and put the VLOOKUP inside an EVALUATE which worked fine. However when I switched back from R1C1 on the sheet it gave me a type mismatch.

So I tried to use a normal VLOOKUP which also gives type mismatch. Overall, my code is a worksheet change only looking at column J, from there I then need a =VLOOKUP(Target.Offset(,-8),’Sheet2’!A:I,9,0). In normal it needs to be a VLOOKUP(B1,’Sheet2’!A:I,9,0) but the lookup value is relative.

Is it better to use a function? Something like this?

Any suggestions?

Code:
Dim V as String

V = Worksheetfunction.VLOOKUP()
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
How about
Code:
Dim v as String
v = Evaluate("VLOOKUP(" & Target.Offset(, -8).Address & " ,'Records'!A:I,9,0)")
MsgBox v
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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