Last Row not working in vlookup

johnnyb5

Board Regular
Joined
Dec 23, 2014
Messages
89
I'm using a common "Last Row" formula in a VBA macro and it is not working in a "Vlookup" formula even though it works in a "Range Formula".

The lastrow formula is:
Dim LstRw As Long
LstRw = Range("A:CB").Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row

This works in the "Range Formula":
Range("H2").AutoFill Range("H2:H" & LstRw)

It does not work in the "Vlookup Formula"
Range("I2").Formula = "=""Company_""&VLOOKUP(E2,$G$2:$H&LstRw,2,0)"

If I remove the "LstRw" and replace it with a real row number the formula will work however, I need it to be dynamic as the quantity of row numbers will change daily.
Would anyone know how to correct this??
Thank You,
JB
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
LstRow is a VBA variable, so you need to put it outside the formula you're trying to put in the cell.
"=""Company_""&VLOOKUP(E2,$G$2:$H" & LstRw & ",2,0)"
 
Upvote 0
Yes Indeed Starl!!!

It has worked like a charm and I'm continuing my Macro building.
Thanks for your time, patience, and have a Happy New Year!!!
JB
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,928
Members
452,366
Latest member
TePunaBloke

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