why not use sub total function in vba
data in sheet 1 is like as in attachment kate.xlsm
try this macro
Sub subtotalling()
Range("A1").Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(5, 6, 18) _
, Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveWindow.SmallScroll Down:=6
Columns("A:A").Cells.Find(what:="grand total", lookat:=xlWhole).Activate
ActiveCell.EntireRow.Insert
End Sub
Sub undo()
Range("A1").Select
Selection.RemoveSubtotal
Cells.Find(what:="grand total", lookat:=xlWhole).Activate
ActiveCell.EntireRow.Delete
End Sub
Bookmarks