How can I use VBA to copy data from sheet1 to sheet 2, with a condition that if the value from column G changes, I insert a new row on sheet 2 below the row holding that last value but above the row holding the next value? Sample input is given, with sample output highlighting the inserted row. Getting all the right columns on the output sheet I can do myself, but the logic for the row insert is giving me trouble.
Dim dataSheet As Worksheet
Dim lastRow As Long, r As Long
Set dataSheet = ActiveSheet 'Worksheets("Sheet1")
With dataSheet
lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
For r = lastRow To 2 Step -1
'compare current row column G to previous row column G, if not the same value, insert row between the two rows
.Rows(r + 1).Resize(UBound + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End If
Next

