Run formula in VBA until last row

evenyougreg

New Member
Joined
Oct 1, 2020
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I'm trying to get this formula to run from D2 until the last detected row, and without using hard coded numbers like D2 until D1243 or whatever because the dataset changes all the time. I've had issues in the past with this on another forum so I will try my luck here.

the formula is

Excel Formula:
=XLOOKUP(INDIRECT("A2:A" & COUNTA(A:A)),VMs!A:A,VMs!B:B,"Not Found")

and the VBA code I have only populates D2, but would like it to run until the last row...

VBA Code:
Range("D2").Formula = "=XLOOKUP(INDIRECT(""A2:A"" & COUNTA(A:A)),VMs!A:A,VMs!B:B,""Not Found"")"

Any thoughts?:unsure:o_O
 
Glad we could help & thanks for the feedback.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Sorry, I only gave you the related part, figuring you'd add the rest, including declaring i As Integer. Plus, it has to be code behind the sheet, not the workbook. So no idea where you put it thus don't know what the missing object is. Perhaps a sheet reference? Aside from that, I must have misunderstood the problem because I don't see how that helps when part of the range is hard coded (the 2 in A2) which is what I thought you didn't want. Glad you got it solved anyway.
 
Upvote 0

Forum statistics

Threads
1,223,671
Messages
6,173,737
Members
452,533
Latest member
Alex19k

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