+ Reply to Thread
Results 1 to 2 of 2

how do i delete rows when cells meet certain criteria?

  1. #1
    Registered User
    Join Date
    07-18-2005
    Posts
    4

    Question how do i delete rows when cells meet certain criteria?

    I want to delete rows 3 - 5 if the value in column b (of any of the respective rows) is zero. Below is the code that I am using but it is not working. It is leaving one of the "zero rows" in place (it is only deleting two of the rows when all three should be deleted). Any help would be greatly appreciated.

    Dim myRng As Range
    Dim zerocell As Range
    Set myRng = Range("b3:b5")
    For Each zerocell In myRng
    If zerocell.Text = "0" Then
    zerocell.EntireRow.Delete
    End If
    Next

    I've also tried this (and I have the same problem):

    Dim myRng As Range
    Dim zerocell As Range
    Set myRng = Range("b3:b5")
    For Each zerocell In myRng
    If zerocell = 0 Then
    zerocell.EntireRow.Delete
    End If
    Next
    _________________
    Thanks, TB

  2. #2
    Tom Ogilvy
    Guest

    Re: how do i delete rows when cells meet certain criteria?

    if application.countif(Range("B3:B5"),0) > 0 then
    rows(3).Resize(3).Delete
    End if

    --
    Regards,
    Tom Ogilvy

    "Tbal" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I want to delete rows 3 - 5 if the value in column b (of any of the
    > respective rows) is zero. Below is the code that I am using but it is
    > not working. It is leaving one of the "zero rows" in place (it is only
    > deleting two of the rows when all three should be deleted). Any help
    > would be greatly appreciated.
    >
    > Dim myRng As Range
    > Dim zerocell As Range
    > Set myRng = Range("b3:b5")
    > For Each zerocell In myRng
    > If zerocell.Text = "0" Then
    > zerocell.EntireRow.Delete
    > End If
    > Next
    >
    > I've also tried this (and I have the same problem):
    >
    > Dim myRng As Range
    > Dim zerocell As Range
    > Set myRng = Range("b3:b5")
    > For Each zerocell In myRng
    > If zerocell = 0 Then
    > zerocell.EntireRow.Delete
    > End If
    > Next
    > _________________
    > Thanks, TB
    >
    >
    > --
    > Tbal
    > ------------------------------------------------------------------------
    > Tbal's Profile:

    http://www.excelforum.com/member.php...o&userid=25317
    > View this thread: http://www.excelforum.com/showthread...hreadid=395819
    >




+ 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