Long winded but easy to understand and also easy to maintain/change.
Sub Or_Maybe_So()
Dim lr As Long, i As Long, ttl As Long
Dim rng As Range
lr = Cells(Rows.Count, 1).End(xlUp).Row
ttl = WorksheetFunction.Sum(Cells(2, 4).Resize(lr - 1))
Application.ScreenUpdating = False
For i = lr To 3 Step -1
If Cells(i, 1).Value <> Cells(i - 1, 1).Value Or _
Cells(i, 2).Value <> Cells(i - 1, 2).Value Or _
Cells(i, 3).Value <> Cells(i - 1, 3).Value Then Cells(i, 1).Resize(, 4).Insert Shift:=xlDown
Next i
For Each rng In Range("A2:D" & Rows.Count).SpecialCells(xlConstants).Areas
With rng.Cells(1).Offset(rng.Rows.Count)
.Value = "Subtotal"
.Font.Bold = True
End With
With rng.Cells(1).Offset(rng.Rows.Count, rng.Columns.Count - 1)
.Formula = "=Sum(R[-" & rng.Rows.Count & "]C:R[-1]C)"
.Value = .Value
.Font.Bold = True
End With
Next rng
With Cells(Rows.Count, 1).End(xlUp).Offset(1)
.Value = "Total"
.Font.Bold = True
With .Offset(, 3)
.Value = ttl
.Font.Bold = True
End With
End With
Application.ScreenUpdating = True
End Sub
Bookmarks