I want to do the cumulative sum from Column 21 to 29
So the value in column 21 should be
(subtotal 20 + subtotal 21) = New value in column 21
The value in columns 22 should be
New value in column 21 + subtotal 22
And so on....
Microsoft Excel
Last Comment
dlmille
8/22/2022 - Mon
dlmille
There is no cumulative function in the group subtotal command, however, what happens as you probably know is when that command is executed, Excel goes in and inserts rows/columns adding the subTotal() function.
So at this point, you merely need to go through that function row/column and update it.
Do you have a brief example spreadsheet that goes with this code? I can better/more quickly help with this conversion if you'd post one.
Thanks,
Dave
fitaliano
ASKER
There you go Dave, what I am trying to do is the progressive cumulative Cash Flow from 2006 to 2015. Subtotal-Example.xls
dlmille
That's from U to AC? I don't speak column numbers, so just confirming...
Option ExplicitSub cumlSubtotals()Dim wkb As WorkbookDim wks As WorksheetDim lastRow As LongDim r As RangeDim rRow As RangeDim rng As Range Set wkb = ThisWorkbook Set wks = wkb.Sheets("Dashboard") lastRow = wks.Range("A" & wks.Rows.Count).End(xlUp).Row Set rng = wks.Range(wks.Range("U4:AC4"), wks.Range("U" & lastRow, "AC" & lastRow)) For Each rRow In rng.Rows For Each r In Range(rRow.Address) If Not r.Formula Like "=SUBTOTAL*" Then 'assume entire row to find has the subtotals, so save time skipping out if not Exit For Else 'found the subtotal row r.Formula = "=" & r.Offset(, -1).Address & " + " & Right(r.Formula, Len(r.Formula) - 1) End If Next r Next rRowEnd Sub
So at this point, you merely need to go through that function row/column and update it.
Do you have a brief example spreadsheet that goes with this code? I can better/more quickly help with this conversion if you'd post one.
Thanks,
Dave