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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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