I am trying to using an input box to ask "how many rows to be entered?" then insert X number of blank rows between existing data only when the value changes in column B.
For example, user states 5 in the input box - then 5 rows would be inserted between Row 5 and 6, Rows 8 and 9, Rows, 11 and 12, etc.
I can insert one row using the code below, however would like the number to be variable. If I try to run it more than once it provides more than one row beyond the second execution.
Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row To 4 Step -1
If Cells(lRow, "B") <> Cells(lRow - 1, "B") Then Rows(lRow).EntireRow.Insert
Next lRow
End Sub
Any help would be greatly appreciated.
For example, user states 5 in the input box - then 5 rows would be inserted between Row 5 and 6, Rows 8 and 9, Rows, 11 and 12, etc.
I can insert one row using the code below, however would like the number to be variable. If I try to run it more than once it provides more than one row beyond the second execution.
Sub InsertRowAtChangeInValue()
Dim lRow As Long
For lRow = Cells(Cells.Rows.Count, "B").End(xlUp).Row To 4 Step -1
If Cells(lRow, "B") <> Cells(lRow - 1, "B") Then Rows(lRow).EntireRow.Insert
Next lRow
End Sub
Any help would be greatly appreciated.