Grup and subtotal in VBA
I used this one for subtotals
Sub sub_total()
Dim iLastRow As Long
Dim iTotal As Long
Dim i As Long
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 & ")"
Cells(iTotal + 1, "i").Value = _
"1"
iTotal = i - 1
End If
Next i
End Sub
On the Subtotal row I added "1" on "i" column, then I filtred the rows
on "1" column and deleted the rest.
Thanks for sugestions!
|