VBA Last Column but specific row for formula?

ExcelNoob222

Board Regular
Joined
Jun 17, 2020
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I need to put a formula in the last column of a specific row and then I need that formula to be dragged down to the last row. However I am stuck. I currently have the code:

VBA Code:
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Rows(2).Find("*", , xlValues, , xlByColumns, xlPrevious).Offset(, 1).Formula = "=SUMIFS($R$4:$R$9,$O$4:$O$9,A2)"

This will find the last column in Row 2 and place the formula there. But how do I then get that formula to drag all the way down? Thanks!
 

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
VBA Code:
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Cells(2, Columns.Count).End(xlToLeft).Offset(, 1).Resize(lastrow - 1).Formula = "=SUMIFS($R$4:$R$9,$O$4:$O$9,A2)"
 
Upvote 0
Solution
How about
VBA Code:
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Cells(2, Columns.Count).End(xlToLeft).Offset(, 1).Resize(lastrow - 1).Formula = "=SUMIFS($R$4:$R$9,$O$4:$O$9,A2)"

Perfect! Thanks for your help.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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