+ Reply to Thread
Results 1 to 6 of 6

Delete rows based on cells that equal zero

  1. #1
    Registered User
    Join Date
    03-21-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    90

    Delete rows based on cells that equal zero

    I have a worksheet (Sheet1) that I want to write code for that searches column G for all the cells that equals zero. Then I want the code to delete those rows that contains zero in column G.

    Here is what I came up with so far but I get a complie error at "Range(r).EntireRow.Select"


    Please Login or Register  to view this content.
    Last edited by jadown; 01-04-2011 at 10:59 AM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Delete rows based on cells that equal zero

    Hi jadown, you are violating Rule three of the forum rules. Please wrap your code with code tags to make it better for us to assist you.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    03-21-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    90

    Re: Delete rows based on cells that equal zero

    Sorry I forgot to put the code tags.

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Delete rows based on cells that equal zero

    I'm struggling a bit to understand what you are trying to do with the the code you've written but this is the basic idea how to conditionally delete rows by looping through them:

    Please Login or Register  to view this content.

    Note that I am looping backwards through the rows otherwise it won't work properly.

    Another option is to use autofilter and then just delete the visible cells. If you do a search of the forum you should find plenty of examples.

    Please remember to use code tags when posting code to the forum as well.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  5. #5
    Registered User
    Join Date
    03-21-2010
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    90

    Re: Delete rows based on cells that equal zero

    I just want the rows to be deleted that is <= zero in column G. But I want these columns to be deleted without leaving empty rows through out the spreadsheet.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Delete rows based on cells that equal zero

    Just change this:

    Please Login or Register  to view this content.

    to this:

    Please Login or Register  to view this content.

    Dom

+ 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