Sum column with variable data VBA

cmschmitz24

Board Regular
Joined
Jan 27, 2017
Messages
150
I need to have my formula sum all of the column, but the data is variable.

My formula is:
Range("P2:R2").FormulaR1C1 = "=+SUM(R[2]C:R[298]C)"

but I could have more or less than 300 rows

I typically use something like this for variable data but I am not sure how to apply it to my formula:
("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)

Thanks!
 

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.
Identify a column that you can use to determine the last row.
Let's say it is column P. Then find the last row like this:
Code:
lastRow = Cells(Rows.Count,"P").End(xlUp).Row
Then, apply it in your formula like this:
Code:
[COLOR=#333333]Range("P2:R2").FormulaR1C1 = "=SUM(R[2]C:R[" & lastRow-2 & "]C)"[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

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