Sometimes we need to put empty rows in excel for every change in id/values in a column. Below macro helps us to put empty rows for every change in values in column A.
Sub InsertRows()
Dim r As Long, mcol As String, i As Long
' find last used cell in Column A
r = Cells(Rows.Count, "A").End(xlUp).Row
' get value of last used cell in column A
mcol = Cells(r, 1).Value
' insert rows by looping from bottom
For i = r To 2 Step -1
If Cells(i, 1).Value <> mcol Then
mcol = Cells(i, 1).Value
Rows(i + 1).Insert
End If
Next i
End Sub
Always b sure that the value, based on which the row is to be added, must be in column A.
Kudos.
No comments:
Post a Comment