Sum range of cells in active cell

BYURAZORBACK

New Member
Joined
Nov 28, 2012
Messages
1
I have a report that comes out daily and has a different number of rows each day. I need to have the vba code that will calculate the sum for a range of cells. The first cell should always be Q4. I have used auto fill to copy a formula down using Range("Q4:Q" & lastRow), but I'm not sure how to use that properly here. Currently I'm using: ActiveCell.FormulaR1C1 = "=SUM(R[-16]C[0]:R[-1]C[0])"
Only because 16 rows up worked the first day I created this.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I have a report that comes out daily and has a different number of rows each day. I need to have the vba code that will calculate the sum for a range of cells. The first cell should always be Q4. I have used auto fill to copy a formula down using Range("Q4:Q" & lastRow), but I'm not sure how to use that properly here. Currently I'm using: ActiveCell.FormulaR1C1 = "=SUM(R[-16]C[0]:R[-1]C[0])"
Only because 16 rows up worked the first day I created this.
Try:
Code:
lastRow = Range("Q" & Rows.Count).End(xlUp).Row
ActiveCell.Formula = "=SUM(" & Range("Q4:Q" & lastRow).Address(1, 1) & ")"
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

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