macro

E

Esrei

I have got a spreadsheet with rows sorted by codes in
column A., from row 2.
From row 2 I need to check the code and every time the
code changes insert a line above the new code, and then
copy row 1 onto the blanck rows.
 
F

Frank Kabel

Hi
try the following macro:

Sub insert_rows()
Dim lastrow As Long
Dim row_index As Long
Application.ScreenUpdating = False
lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For row_index = lastrow - 1 To 2 Step -1
If Cells(row_index, "A").Value <> _
Cells(row_index + 1, "A").Value Then
Cells(row_index + 1, "A").EntireRow.Insert _
(xlShiftDown)
Rows(1).Copy Destination:=Rows(row_index + 1)
End If
Next
Application.ScreenUpdating = True
End Sub
 
Top