+ Reply to Thread
Results 1 to 14 of 14

Delete blank rows between blocks of data except two blank rows

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Delete blank rows between blocks of data except two blank rows

    Hello everyone
    I have a range between columns C and H and in column E there is data and inbetween data there are different number of blank rows
    How can I remove the blank rows (between C and H only) and at the same time leave two blank rows

    I have put before and after ..to make it clear
    Thanks advanced for help
    Attached Files Attached Files
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: Delete blank rows between blocks of data except two blank rows

    Hi Yasser,

    Try this (though initially on a copy of your data as the results cannot be undone if they're not as expected):

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼

    Quote Originally Posted by YasserKhalil View Post
    How can I remove the blank rows (between C and H only) and at the same time leave two blank rows
    A classic EZ way :

    PHP Code: 
    Sub Demo1()
                
    Dim Rg As RangeRf As RangeDZ&
        
    With Sheet1.[B4].CurrentRegion.Offset(, 1).Resize(, 6).Rows
                Set Rg 
    = .Parent.Cells(.Count 45).End(xlUp).CurrentRegion
                Set Rf 
    Rg.End(xlUp)
           Do 
    Until Rf.Row 4
                    DZ 
    Rg.Row Rf.Row 3
                 
    If DZ 0 Then .Item(Rf.Row 2).Resize(DZ).Delete xlShiftUp
                Set Rg 
    Rf.CurrentRegion
                Set Rf 
    Rg.End(xlUp)
           
    Loop
        End With
                Set Rg 
    Nothing:  Set Rf Nothing
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete blank rows between blocks of data except two blank rows

    Thanks a lot for replies ..
    @Mr. MarcL
    I am lost in fact .. How can I edit your code to work with columns E ...regardless relying on column B current region ..
    And in this loop I think rows will be delete one by one ... I have about 50,000 rows so I think this will be slow

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete blank rows between blocks of data except two blank rows

    Thanks a lot Mr. Trebor for your working solution
    Thank you very much

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Delete blank rows between blocks of data except two blank rows

    Yasser,

    thanks for the rep' !

    Did you try my code with your sample workbook joined ?
    As it rocks on my side so already working with column E ! (Just check Rf & Rg address …)
    And rows are not deleted one by one but by blocks as you can see within my code !

    Of course as a demonstration, you can mod it in order to work faster by desactivating display (via ScreenUpdating)
    or rewrite the engine via a formula and a sort as you already saw recently in a previous thread …

    The code was made upon informations given in your initial post so we couldn't guess those 50 000 rows !

    The better initial post, the better code …
    Last edited by Marc L; 03-25-2018 at 10:00 PM.

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete blank rows between blocks of data except two blank rows

    Hi Yasser,

    I wrote one too

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete blank rows between blocks of data except two blank rows

    Thanks a lot my friend
    I appreciate your solution a lot ..

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool As yet shown …


    The fast very EZ beginner way, formula at child level :

    PHP Code: 
    Sub Demo2()
             
    Application.ScreenUpdating False
        With Sheet1
    .Range("C4:H" Split(Sheet1.UsedRange.Address"$")(4))
             
    With .Columns(6):  .Formula "=AND(E4=0,E2=0)":  .Formula = .Value:  End With
            
    .Sort .Cells(6), xlAscendingHeader:=xlNo
            
    .Columns(6).ClearContents
        End With
             Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Delete blank rows between blocks of data except two blank rows

    Yes Mr. Marc
    That's the best (child level is the best approach) but we can't think as children as they are more creative than adults
    Best Regards

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Delete blank rows between blocks of data except two blank rows


    In fact it's the manual way when directly operating within worksheet, faster than creating any code !

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Delete blank rows between blocks of data except two blank rows

    You're welcome old friend and thanks for the rep!

  13. #13
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,523

    Re: Delete blank rows between blocks of data except two blank rows

    Thanks for my rep too

  14. #14
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Delete blank rows between blocks of data except two blank rows


    The same, thanks again Yasser for the new rep' !

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 11
    Last Post: 07-30-2015, 12:35 PM
  2. [SOLVED] Delete blank rows between data rows, shift rows up, then repeat
    By excelactuary in forum Excel General
    Replies: 2
    Last Post: 03-11-2013, 11:53 AM
  3. [SOLVED] VBA Find last row and column that contain data and delete all blank rows and blank columns
    By bcn1988 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-03-2012, 01:07 PM
  4. [SOLVED] How to Delete Multiple Consecutive Blank Rows - Delete all Blank Rows
    By raw_geek in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-16-2012, 03:17 PM
  5. [SOLVED] Delete blank rows after filter - if no blank rows exit sub
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-27-2012, 10:00 AM
  6. Replies: 1
    Last Post: 05-10-2012, 04:58 PM
  7. Delete Blank Rows-Blank Row between my data range
    By Bob@Sun in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-27-2010, 02:52 PM

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