[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]
[color=darkblue]Sub[/color] test()
[color=darkblue]Dim[/color] SearchRng [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] FoundCell [color=darkblue]As[/color] Range
[color=darkblue]Dim[/color] FirstAddress [color=darkblue]As[/color] [color=darkblue]String[/color]
[color=darkblue]Dim[/color] SummaryBelow [color=darkblue]As[/color] [color=darkblue]Boolean[/color]
SummaryBelow = [color=darkblue]True[/color]
[color=seagreen]'Sort the data[/color]
[color=darkblue]With[/color] Range("A1", Cells(Rows.Count, "B").End(xlUp))
.Sort key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
[color=darkblue]End[/color] [color=darkblue]With[/color]
[color=seagreen]'Subtotal the data[/color]
Range("A1").CurrentRegion.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(2), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=SummaryBelow
[color=darkblue]Set[/color] SearchRng = Intersect(ActiveSheet.UsedRange, Columns("A"))
[color=seagreen]'Format the data[/color]
[color=darkblue]With[/color] SearchRng
[color=darkblue]Set[/color] FoundCell = .Find("* Total", LookIn:=xlValues, lookat:=xlWhole)
[color=darkblue]If[/color] [color=darkblue]Not[/color] FoundCell [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
FirstAddress = FoundCell.Address
[color=darkblue]Do[/color]
[color=darkblue]With[/color] FoundCell.Offset(, 1).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
[color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]With[/color] FoundCell.Offset(, 1).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
[color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]If[/color] InStr(FoundCell, "Grand") > 0 [color=darkblue]Then[/color]
[color=darkblue]If[/color] SummaryBelow [color=darkblue]Then[/color] FoundCell.Offset(2).Select
[color=darkblue]Else[/color]
[color=darkblue]If[/color] SummaryBelow = [color=darkblue]True[/color] [color=darkblue]Then[/color]
FoundCell.Offset(1, 1).EntireRow.Insert
[color=darkblue]Else[/color]
FoundCell.Offset(, 1).EntireRow.Insert
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]Set[/color] FoundCell = .FindNext(FoundCell)
[color=darkblue]Loop[/color] [color=darkblue]While[/color] FoundCell.Address <> FirstAddress
[color=darkblue]End[/color] [color=darkblue]If[/color]
[color=darkblue]End[/color] [color=darkblue]With[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]