Consulting

Results 1 to 12 of 12

Thread: Solved: Delete Empty Rows

  1. #1

    Question Solved: Delete Empty Rows

    I have seen a bazillion versions of this very popular sub, which satisfy multitudes of criteria. My compliments to those who are clever enough to figure them out.

    My needs are quite simple: delete all empty rows between (say) A1 and T1000.

    Any help would be greatly appreciated!

    Thanks -

    Sting Ray
    Last edited by StingRay; 04-08-2007 at 12:31 AM. Reason: Data File Added

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Dim i As Long
    With ActiveSheet

    For i = 1000 To 1 Step -1

    If Application.CountBlank(.Cells(i, "A").Resize(, 20)) = 20 Then
    .Rows(i).Delete
    End If

    Next i

    End With

    End Sub
    [/vba]

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    or possibly
    [VBA] If Application.CountBlank(.Cells(i, "A").Resize(, 20)) = 20 Then
    .Cells(i, "A").Resize(, 20).Delete Shift:=xlUp
    End If
    [/VBA]
    if columns greater than T are to be preserved.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    isn't this similar to that which you indicated in another thread MD? What Bob has written is very close to that which you said was a preferred way.

    Delete from the right or in this case from the bottom.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  5. #5
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi Ted,
    No difference in the methodology, but the OP does not say he wants to delete entire rows
    Quote Originally Posted by StingRay
    My needs are quite simple: delete all empty rows between (say) A1 and T1000.
    I have quite a few spreadsheets with many rows in say, columns A:H, summarised in columns N1:P30. Although I may want to delete all blank rows in A:H,. I need to preserve all my summary area, so restrict the deletion using the resize function.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    Yes I agree, for the op has indicated the size of the range A1:T1000.
    hence the use of the .Resize(, 20) to restrict the range to column T right?

    Quote Originally Posted by xld
    [vba]

    Public Sub ProcessData()
    Dim i As Long
    With ActiveSheet

    For i = 1000 To 1 Step -1

    If Application.CountBlank(.Cells(i, "A").Resize(, 20)) = 20 Then
    .Rows(i).Delete
    End If

    Next i

    End With

    End Sub
    [/vba]
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  7. #7
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Bob's code will delete entire rows
    .rows(i).delete

    My code will delete only from columns A:T
    .Cells(i, "A").Resize(, 20).Delete Shift:=xlUp

    Either could be correct for the OP.

    See the difference.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    Many thanks to all of you!

    I now have a much improved personal KB -

    StingRay

  9. #9
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mdmackillop
    Bob's code will delete entire rows
    .rows(i).delete

    My code will delete only from columns A:T
    .Cells(i, "A").Resize(, 20).Delete Shift:=xlUp

    Either could be correct for the OP.

    See the difference.
    He may not have said delete entire rows, but probably because that nuance did not occur to him, whereas he did say delete rows, not delete cells.

  10. #10
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    What would the result be if he had said "delete all empty cells between (say) A1 and T1000."
    I did delete rows, not cells, but limited to the specified range.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  11. #11
    Being a Newbie, I was not aware of all the nuances! Since my worksheet is quite small (Columns A thru T, Rows 1 thru 1,000), I only needed an economical solution.

    Thanks Again to All -

    StingRay

  12. #12
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Thanks Stingray,
    A lot of questions are open to interpretation, so different solutions may be offered.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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