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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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