Grup and subtotal in VBA
Hi Orhan,
the easiest way is to copy the subtotals row and insert it again, but
only as values. If you need to do that part automatically, use
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
ActiveSheet.Paste
Application.CutCopyMode = False
My suggestion would be not to delete the details, but copy values of
the subtotals row into a kind of consolidation worksheet which is
different from the calculation sheet. That could be - for the sake of
file size - another file, you could also use a separate sheet.
Good luck
Udo
Orhan schrieb:
Hi,
I run the macro, but my computer crashes, so anyway I found this one
witch works
Sub sub_total()
iLastRow = Cells(Rows.Count, "g").End(xlUp).Row
iTotal = iLastRow
For i = iLastRow To 2 Step -1
If Cells(i, "g").Value < Cells(i - 1, "g").Value Then
Rows(iTotal + 1).Insert
Cells(iTotal + 1, "k").Formula = _
"=SUM(D" & i & ":D" & iTotal & ")"
iTotal = i - 1
End If
Next i
End Sub
It inserts a new row with subtotal after each group.
But how can I delete the rest and keep only the subtotal row?
Thanls!
|