Sub FormatHeaderChunk()
Dim rng As Range
Dim cell As Range
Dim FirstAddress As String
Dim LastRow As Long
Dim LastCol As Long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
LastCol = Cells(3, Columns.Count).End(xlToLeft).Column
Call FormatCells(Range("A3"), LastCol)
With Columns("A:C")
Set cell = .Find("Total", Lookat:=xlPart)
If Not cell Is Nothing Then
FirstAddress = cell.Address
Do
Call FormatCells(cell, LastCol)
Set cell = .FindNext(cell)
Loop While Not cell Is Nothing And cell.Address <> FirstAddress
End If
End With
Range("A3").Resize(LastRow - 2, LastCol).BorderAround LineStyle:=xlContinuous, ColorIndex:=xlColorIndexAutomatic
End Sub
Private Function FormatCells(rng As Range, NumCols As Long)
With rng.Resize(, NumCols - rng.Column + 1)
.Borders(xlDiagonalDown).LineStyle = xlNone
.Borders(xlDiagonalUp).LineStyle = xlNone
With .Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
With .Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
With .Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.Weight = xlThin
End With
.Borders(xlInsideHorizontal).LineStyle = xlNone
With .Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
End With
.Font.Bold = True
End With
End Function