+ Reply to Thread
Results 1 to 12 of 12

Insert a Blank Row at every other row where active cell <> X or <> Y etc

Hybrid View

  1. #1
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Insert a Blank Row at every other row where active cell <> X or <> Y etc

    Hi all,

    Firstly, I totally disagree with having to do this but due to politics I have no choice 

    I need to insert a blank row in-between every other row of data, however, not if the active cell in column A contains “Dean” or “Bob” or “Fred” etc.
    Is this possible?

    Today there might be 20 rows tomorrow there might be 50 so I only want to loop the number of times for the data in column A

    Thanks in advance

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    I hope you are not related in any way to the Chancellor of the exchequer.
    Give this a try

    Sub InsertRows()
    Dim LR As Long, i As Long
    
        Application.ScreenUpdating = False
        LR = Range("A" & Rows.Count).End(xlUp).Row
        
        For i = LR To 1 Step -2
            If InStr(Cells(i, "A"), "Dean") = 0 Or InStr(Cells(i, "A"), "Bob") = 0 Or InStr(Cells(i, "A"), "Fred") = 0 Then
            Rows(i).Insert Shift:=xlDown
            End If
        Next i
        
        Application.ScreenUpdating = True
    
    End Sub

  3. #3
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    Thanks for such a quick responce, and no, I'm not realted to that......

    It is sort of working, it is inserting a line inbetween every 2 rows

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    If you want in every row, change this line

    For i = LR To 1 Step -2
    INTO

    For i = LR To 1 Step -1

  5. #5
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    Hi,

    I have done this and noticed that it is ignoring the line where <> Bob <> Dean <> Fred

    just inserting aline inbetween all.

    Column A
    Bob
    Bob
    Bob
    Bob
    Bob
    Bob
    Danny
    Danny
    Danny
    Dave
    Dave
    Dave
    Dean
    Dean
    Dean
    Dean
    Dean
    Dean
    Fred
    Fred
    Fred
    Fred
    Fred
    Fred
    James
    James
    James
    James
    James
    James
    Mary
    Mary
    Mary

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    I have attached you data in excel. There are two sheets, Ori sheet before running the code and the second after. Could you indicate with a sample what the result would be, so that I can adjust my code
    Attached Files Attached Files
    Last edited by AB33; 03-21-2013 at 01:44 PM.

  7. #7
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    Hi,

    Its neither, if the name is Bob, or Fred, or Dean I do not want any spaces inserted, if it isnt any of them then i want a space inserted, makes sense?

    i.e. on the ORI sheet A7 - A12 would have a spaces in-between but A13-A18 wouldnt

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    I have done a sample book for you. All you have to do is to just show me your expected result. Otherwise, it is going to be guess work

  9. #9
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    Hi,

    I cant upload documents due to my companies internet policy but i have amended in excel and then posted in here so hopefully when you paste into a worksheet it will stay with the spaces:

    Bob
    Bob
    Bob
    Bob
    Bob
    Bob

    Danny

    Danny

    Danny

    Dave

    Dave

    Dave

    Dean
    Dean
    Dean
    Dean
    Dean
    Dean
    Fred
    Fred
    Fred
    Fred
    Fred
    Fred

    James

    James

    James

    James

    James

    James

    Mary

    Mary

    Mary

    Thanks

  10. #10
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    Try this one

    Sub InsertRows()
    Dim LR As Long, i As Long
    
        Application.ScreenUpdating = False
        LR = Range("A" & Rows.Count).End(xlUp).Row
        
        For i = LR To 1 Step -1
            If InStr(Cells(i, "A"), "Dean") = 0 And InStr(Cells(i, "A"), "Bob") = 0 And InStr(Cells(i, "A"), "Fred") = 0 Then
            Rows(i).Insert Shift:=xlDown
            End If
        Next i
        
        Application.ScreenUpdating = True
    
    End Sub

  11. #11
    Registered User
    Join Date
    11-26-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    This is perfect, thank you so much. Thanks for taking the time to help.

    regards,

    Dean

  12. #12
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Insert a Blank Row at every other row where active cell <> X or <> Y etc

    Dean,
    You are welcome!
    Could you please now close this thread as solved? Go in to the top right hand of this page, choose "Thread Tools" from the menu, then select "Solved" from the drop down menu.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1