This should work (assuming your data is in Column A):
Sub insertHeaderRow()
Application.ScreenUpdating = False
Dim lastRow As Long, i As Long
Dim cel As Range
Dim myTest As String
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lastRow To 1 Step -1
Set cel = Cells(i, 1)
mytext = Mid(cel, InStrRev(cel, "\") + 1, 256) & ":"
On Error Resume Next
If cel.Value <> cel.Offset(-1, 0).Value Or cel.Row = 1 Then
cel.EntireRow.Insert
cel.Offset(-1, 0).Value = mytext
colorHeaderRow cel.Offset(-1, 0)
' Double header row height
cel.Offset(-1, 0).RowHeight = cel.Offset(-1, 0).RowHeight * 2
End If
On Error GoTo 0
Next i
Application.ScreenUpdating = True
End Sub
Private Sub colorHeaderRow(ByVal cel As Range)
With cel.EntireRow.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With cel.EntireRow.Font
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
End Sub
Note: If someone has any idea how to avoid using the On Error Resume Next (without making the code much longer), I'd appreciate it. I only used it because at row 1, the cel.offset(-1,0).Value throws an (expected) error and doesn't look at the rest of the statement. I used the Resume Next so it'll ignore that, and see the cel.Row = 1 and add the final row. I've just had it drilled in to my head to avoid error handling like this...but the code shouldn't throw any other errors.