Dear all,
This is the code I found on internet. How can I modify it so that it compares with multiple values? I.e. insert a row if there value change not only in "A" column, but also it there is a change of value in "B" column as well?
Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") <> Cells(lRow - 1, "A") Then Rows(lRow).EntireRow.Insert
Next lRow
End Sub
This is how the data looks like..
A B C D E F
4 4 IV 6 1978 1
4 4 IV 6 1978 2
5 4 IV 6 1978 3
5 4 IV 6 1978 4
5 4 IV 6 1978 5
5 6 IV 6 1978 6
5 6 IV 6 1978 7
4 4 IV 6 1978 8
4 4 IV 6 1978 9
And this is how it should look like
A B C D E F
4 4 IV 6 1978 1
4 4 IV 6 1978 2
5 4 IV 6 1978 3
5 4 IV 6 1978 4
5 4 IV 6 1978 5
5 6 IV 6 1978 6
5 6 IV 6 1978 7
4 4 IV 6 1978 8
4 4 IV 6 1978 9
This is the code I found on internet. How can I modify it so that it compares with multiple values? I.e. insert a row if there value change not only in "A" column, but also it there is a change of value in "B" column as well?
Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row To 2 Step -1
If Cells(lRow, "A") <> Cells(lRow - 1, "A") Then Rows(lRow).EntireRow.Insert
Next lRow
End Sub
This is how the data looks like..
A B C D E F
4 4 IV 6 1978 1
4 4 IV 6 1978 2
5 4 IV 6 1978 3
5 4 IV 6 1978 4
5 4 IV 6 1978 5
5 6 IV 6 1978 6
5 6 IV 6 1978 7
4 4 IV 6 1978 8
4 4 IV 6 1978 9
And this is how it should look like
A B C D E F
4 4 IV 6 1978 1
4 4 IV 6 1978 2
5 4 IV 6 1978 3
5 4 IV 6 1978 4
5 4 IV 6 1978 5
5 6 IV 6 1978 6
5 6 IV 6 1978 7
4 4 IV 6 1978 8
4 4 IV 6 1978 9
Last edited: