+ Reply to Thread
Results 1 to 7 of 7

Delete Rows based on Criteria

  1. #1
    Registered User
    Join Date
    07-18-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    6

    Delete Rows based on Criteria

    I have a huge spreadsheet importing data from a text file (~60,000 rows of data). It is a lot of information that is recorded in real time and I need to delete rows that have erroneous values (negative, below or above a certain threshold). I need a quick way to process a large number of rows and delete all of the rows that I don't want based on the entered criteria.

    Here is the VBA I have so far just for one criteria, but it's incredibly slow for a lot of rows already.

    Please Login or Register  to view this content.
    I attached an example spreadsheet. To explain the example...I need the VBA to check if the value of A30 is less than B16 or greater than C16, and if so, delete that row. Then move to the next criteria--if B30 is less than B17 or greater than C17, delete that row, etc. through all of the criteria. Then I need it to do the same thing for every row, leaving only the rows that meet all of the criteria.
    Attached Files Attached Files
    Last edited by amandaca; 07-19-2011 at 11:10 AM.

  2. #2
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Mexico
    Posts
    200

    Re: Delete Rows based on Criteria

    Try Autofilter:
    http://www.rondebruin.nl/delete.htm

  3. #3
    Registered User
    Join Date
    07-18-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Delete Rows based on Criteria

    That only gives me a filter for specific values, and it doesn't specify in which column it's looking for the value. Autofilter seems like a good method for a large number of rows but that code has a "DeleteValue" that is set to a specific value. I'm not that great with programming and can't figure out how to include all of the ranges I need and to make it look for each value only within a single column,

  4. #4
    Registered User
    Join Date
    07-18-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Delete Rows based on Criteria

    Please Login or Register  to view this content.
    This is what I've come up with so far, but it still takes at least 10 seconds to run it for just 1 set of criteria and I'm going to run the same thing for about 10 different categories. Any other ideas for a more efficient loop?
    Last edited by amandaca; 07-19-2011 at 08:46 AM.

  5. #5
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Delete Rows based on Criteria

    Hi and welcome to the board

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Delete Rows based on Criteria

    Please Login or Register  to view this content.



  7. #7
    Registered User
    Join Date
    07-18-2011
    Location
    Houston, TX
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Delete Rows based on Criteria

    I'm not entirely sure how your VBA works. It seems like it's deleting random values from random columns and rows--not following the criteria given by the user-input data table, and not deleting entire rows--it leaves random values. Also, I get a Run-time error 424 - object required.

    Any other suggestions/corrections to snb's code?

    It seems to work fast but I have no idea what it's doing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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