Thanks so much Peter! This works great - I ended up with this:
Sub InsertSubtotals()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ThisWorkbook.Sheets(sheet_I_Onshore_DTB_YTD).Select
ThisWorkbook.Sheets(sheet_I_Onshore_DTB_YTD).Range("A1", Range("A" & Rows.Count).End(xlUp)).Resize(, 18) _
.Subtotal _
GroupBy:=1, Function:=xlSum, TotalList:=Array(1, 10, 11, 13), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
With Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(-1)).SpecialCells(xlConstants)
With .EntireRow.Font
.Bold = True
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
With .EntireRow.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With .EntireRow.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With .EntireRow.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With .EntireRow.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With .EntireRow.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 14671839
.TintAndShade = 0
.PatternTintAndShade = 0
End With
.Offset(, 1).FormulaR1C1 = "=""Subtotal: "" & R[-1]C"
Columns("A").Delete
Columns("A").RemoveSubtotal
End With
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
A very small point - is there a way to limit the formatting to columns A through R. Using .EntireRow obviously applies the borders and colours etc across the whole sheet to column XFD
I was thinking of using something like this afterwards but perhaps you know a neater way?
Sub Removeformatting()
ThisWorkbook.Sheets(sheet_I_Onshore_DTB_YTD).Select
Columns("S:S").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Font.Bold = False
With Selection.Font
.ColorIndex = xlAutomatic
.TintAndShade = 0
End With
End Sub
Thanks again.