Try this version
![]()
Sub InsertRowsV3() Dim lastRow As Long Dim rowPtr As Long Dim strT1 As String Dim strT2 As String Dim shtS As Worksheet Dim shtT As Worksheet Set shtS = ActiveSheet Set shtT = Worksheets.Add shtT.Name = "Output " & Format(Now(), "hh-mm") shtS.UsedRange.Copy shtT.Range("A1").PasteSpecial xlPasteValuesAndNumberFormats strT1 = "Begin-Total" strT2 = "End-Total" With shtT lastRow = .Range("B" & .Rows.Count).End(xlUp).Row .Range("B" & lastRow + 1).Value = strT2 For rowPtr = lastRow To 3 Step -1 If .Range("B" & rowPtr) <> Range("B" & rowPtr - 1) Then .Range("B" & rowPtr).Resize(2).EntireRow.Insert .Range("B" & rowPtr).Value = strT2 .Range("B" & rowPtr + 1).Value = strT1 End If Next rowPtr .Range("B2").EntireRow.Insert .Range("B2").Value = strT1 End With End Sub
Bookmarks