• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to insert blank row when value gets changed

ThrottleWorks

Excel Ninja
Hi,

I have a data set of 15 columns and 4000 rows (approx.).
First column is for dates. Dates in this column (Column A) are sorted to oldest to newest.
I want to insert a blank row if value in column A gets changed.

For example, in original dataset values are as mentioned below.

Range(“A1:O1”) are headers.
Range(“A2:A5”) value = 01-03-2016
Range (“A6:A10”) value= 02-03-2016
Range (“A11:A20”) value= 03-03-2016 and so on

I want to insert a blank row after A5, A10 and A20

Can anyone please help me in this.

Apologies for not uploading sample file, please let me know if you need sample file, I will try to upload it.
 
Hi !​
Code:
Sub Demo1()
    Application.ScreenUpdating = False
For R& = Cells(1).CurrentRegion.Rows.Count - 4 To 6 Step -5
    Rows(R).Insert xlShiftDown
Next
    Application.ScreenUpdating = True
End Sub
 
For example, in original dataset values are as mentioned below.

Range(“A1:O1”) are headers.
Range(“A2:A5”) value = 01-03-2016
Range (“A6:A10”) value= 02-03-2016
Range (“A11:A20”) value= 03-03-2016 and so on

I want to insert a blank row after A5, A10 and A20
One way.
Code:
Sub test()
    Columns(1).Insert
    With Range("b3", Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
        .Formula = "=if(b2<>b3,if(a2=1,""a"",1),"""")"
        .Value = .Value
        On Error Resume Next
        .SpecialCells(2, 1).EntireRow.Insert
        .SpecialCells(2, 2).EntireRow.Insert
        On Error GoTo 0
    End With
    Columns(1).Delete
End Sub
 
Back
Top