VBA insert formula with fixed column but variable row number

JohnZ1156

Board Regular
Joined
Apr 10, 2021
Messages
160
Office Version
  1. 2021
Platform
  1. Windows
I'm trying to get VBA to insert a formula into the active cell with the following line of code where LR is the last Row number

=VLOOKUP(I7021,$R$18:$T$137,2)

To test I entered
MsgBox "I" & lr and it shows the cell I7021 which is column I and row 7021 in the message box.

But when I try to use this line of code to get the following formula entered into the active cell, it doesn’t work.
ActiveCell.Formula = "=VLOOKUP("I" & lr,$R$18:$T$137,2)"

I have a feeling this is an easy one, but I know I'm missing something stupid.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Yep, you're very close to it.

ActiveCell.Formula = "=VLOOKUP(I" & lr & ",$R$18:$T$137,2)"
 
Upvote 0
Solution
Thank you Osvaldo Palmeiro,

I guess I got my quotation marks confused.
I knew I was doing something stupid.

BTW, Happy New Year!!!
 
Upvote 0

Forum statistics

Threads
1,215,708
Messages
6,126,363
Members
449,311
Latest member
accessbob

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