Sum of a dynamic number of rows

LeeB123

New Member
Joined
Aug 29, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hello,

My first post. Currently, I manually paste in my formula for each month to calculate the sum of the "Count" rows and then manually update the range of rows (N4:N6 etc). This is a pain and I am sure it can be easier.
The screen shot is an example, but in reality there are often thousands of rows, making the setting of the row range time consuming and prone to errors. The observation is that the header of the rows is always the same, set to "Count" in the example.

In laymen's terms, I need to dynamically adjust the range according to whether the "Count" header is for that particular month.
For example, pasting the dynamic count formula in to cell N33, I would want it to find the "Count" header of cell N22 and therefore chose the range of N23:N32 dynamically.

Many thanks in advance to you clever folks.

Lee
 

Attachments

  • Example.png
    Example.png
    15.9 KB · Views: 16
Another vba option assuming the numbers in column N are not the result of formulas

VBA Code:
Sub Insert_Formulas()
  Dim rA As Range
  
  For Each rA In Columns("N").SpecialCells(xlConstants, xlNumbers).Areas
    rA.Cells(rA.Count + 1).FormulaR1C1 = "=SUM(R" & rA.Row & "C:R[-1]C)"
  Next rA
End Sub

If the col N values are the result of formulas
Rich (BB code):
For Each rA In Columns("N").SpecialCells(xlFormulas, xlNumbers).Areas
 
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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