Insert Blank line after change in cell data

bradjedis
4StarLounger
Posts: 538
Joined: 30 Mar 2010, 18:49
Location: United States

Insert Blank line after change in cell data

Post by bradjedis »

Greetings,

I have a need to insert a blank row when cell content changes.

data begins in A2. When the cell content changes in col A, insert blank row after last item.

Col A

1234
1234
1234
2345

Row to be inserted after the last 1234. Need to structure thru list, which will vary over time

Thanks!

User avatar
HansV
Administrator
Posts: 78419
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Insert Blank line after change in cell data

Post by HansV »

Run this macro:

Code: Select all

Sub InsertRows()
    Dim r As Long
    Dim m As Long
    Application.ScreenUpdating = False
    m = Range("A" & Rows.Count).End(xlUp).Row
    For r = m To 3 Step -1
        If Range("A" & r).Value <> Range("A" & r - 1).Value Then
            Range("A" & r).EntireRow.Insert
        End If
    Next r
    Application.ScreenUpdating = True
End Sub
Best wishes,
Hans

bradjedis
4StarLounger
Posts: 538
Joined: 30 Mar 2010, 18:49
Location: United States

Re: Insert Blank line after change in cell data

Post by bradjedis »

Perfect! Than you....