+ Reply to Thread
Results 1 to 5 of 5

delete entire blank rows

Hybrid View

isabella delete entire blank rows 08-18-2010, 02:36 AM
TMS Re: delete entire blank rows 08-18-2010, 03:52 AM
isabella Re: delete entire blank rows 08-18-2010, 04:08 AM
Marcol Re: delete entire blank rows 08-18-2010, 04:14 AM
isabella Re: delete entire blank rows 08-18-2010, 09:07 PM
  1. #1
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Thumbs up delete entire blank rows

    Hi there!

    I would like to delete 2 blank rows only before new item.
    What i have done is like this:

    Private Sub btnDelete_Click()
        Range("1:1").SpecialCells(xlCellTypeBlanks).EntireColumn.Delete xlShiftToLeft
        Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete xlShiftUp
    End Sub
    But, this code will delete other rows as well. (You can try in the attachment).
    I have more than 2000 line of rows to do it manually.

    I'm still new in VBA.
    You help are most appreciate. Thanks!
    Attached Files Attached Files
    Last edited by isabella; 08-18-2010 at 09:08 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,198

    Re: delete entire blank rows

    One way, based on your example:

    If Application.WorksheetFunction.CountA( _
        Range("A" & ActiveCell.Row).Resize(2, 5)) = 0 Then
            ActiveCell.Resize(2, 1).EntireRow.Delete
    End If


    You need to select a cell in the row to be deleted before pressing the button.

    Regards

  3. #3
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: delete entire blank rows

    Thank you for your respond TMShucks.

    It works, but I think it is not so practical for the user.

    I have the idea to do like this:
    If the range between A until E is empty, all rows will be deleted.
    I think looping might work but, I still have no luck to do it.

    Anyway, thanks for your help!

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: delete entire blank rows

    Try this

    Private Sub btnDelete_Click()
        Dim LastRow As Long, LastCol As Long
        Dim RowNo As Long, ColNo As Long
        
        LastRow = Range("A" & Rows.Count).End(xlUp).Row
        LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
        
        For RowNo = LastRow To 2 Step -1
            If WorksheetFunction.CountA(Rows(RowNo)) = 0 Then
                Rows(RowNo).EntireRow.Delete
            End If
        Next
        For ColNo = LastCol To 1 Step -1
            If WorksheetFunction.CountA(Columns(ColNo)) = 0 Then
                Columns(ColNo).EntireColumn.Delete
            End If
        Next
    End Sub

    You might need to change this line
       LastRow = Range("A" & Rows.Count).End(xlUp).Row

    to this
        LastRow = ActiveSheet.UsedRange.Rows.Count
    in case column A is not the longest column of data.

    N.B. this also removes blank columns.

    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  5. #5
    Registered User
    Join Date
    08-02-2010
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    55

    Re: delete entire blank rows

    Great!

    Thank you very much Marcol. It works nicely.

+ 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