I need to insert an additional record before the next value in a list changes.
1 4 j
2 4 g
3 5 h
4 5 f
5 5 v
6 5 y
7 5 f
8 6 f
9 6 g
10 8 j
ie Lines 2, 7, 9 would be duplicated and inserted before the next line. Note working is from the bottom up. I thought maybe Selection.Offset(1, 0).Select
Sub InsertRowsWithNewValues()
' Note: hard coded to "Sheet1", ChkCol
Dim LastRowcheck As Long, n1 As Long, ChkCol As Long
ChkCol = 2
MsgBox ("Execute on column: " + Str(ChkCol))
With Worksheets("Sheet1")
LastRowcheck = .Range("A" & .Rows.Count).End(xlUp).Row
For n1 = LastRowcheck To 3 Step -1
MsgBox (.Cells(n1, ChkCol).Value + " " + .Cells(n1 - 1, ChkCol).Value)
If .Cells(n1, ChkCol).Value <> Cells(n1 - 1, ChkCol).Value Then
.Rows(n1).Insert
.Rows(n1 - 1).Select
Selection.Copy
Selection.Insert
' .Rows(n1).Paste
End If
Next n1
End With
End Sub