+ Reply to Thread
Results 1 to 14 of 14

Macro deleting rows based conditional on column data

  1. #1
    Registered User
    Join Date
    08-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2000
    Posts
    22

    Macro deleting rows based conditional on column data

    I need help with a macro that will delete rows based on the value "TRUE" in column I of a spreadsheet. I'm doing something wrong in idenitfying the range in the code and can't get it figured out. Any help would be appreciated.

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro deleting rows based conditional on column data

    It should be fairly simple, but the problem might be that as you delete each row the size of your range changes, which could make a For ... Each ... Next loop throw a bit of a wobbler.

    Why not post your code so far, so we can have a look?

  3. #3
    Registered User
    Join Date
    08-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2000
    Posts
    22

    Re: Macro deleting rows based conditional on column data

    Here is the latest I am working on...

    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro deleting rows based conditional on column data

    Instead of Cells(900,"I") you need to use Cells(rwNum,"I"), otherwise it will loop until row 900 isn't equal to true and then go through the rest of the loop without doing anything.

  5. #5
    Registered User
    Join Date
    08-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2000
    Posts
    22

    Re: Macro deleting rows based conditional on column data

    OK, I did that, but the macro is still not deleting the rows where the value "TRUE" is present in column "I". Could it be because I added the code to an existing macro instead . See a portion of the macro (it's really long, so only sending a bit) below..

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro deleting rows based conditional on column data

    Where is lastrow defined?

    Does column I contain "TRUE" or "True"? Your post and your comment both say "TRUE", but the code is looking for "True".

  7. #7
    Registered User
    Join Date
    08-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2000
    Posts
    22

    Re: Macro deleting rows based conditional on column data

    I guess "Last Row" is not defined, but not sure how to do that. Currently the list has 900 rows, but data will be continuing to be added, so I need make sure that there is space for that. I changed the code to "TRUE" which is what the value actually is, but the rows with "TRUE are still not being deleted when running the macro. Below is the last portion of the macro that I am having trouble with.

    Please Login or Register  to view this content.

  8. #8
    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: Macro deleting rows based conditional on column data

    Try this
    Please Login or Register  to view this content.

    Hope ths 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.

  9. #9
    Registered User
    Join Date
    08-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2000
    Posts
    22

    Re: Macro deleting rows based conditional on column data

    Great! That works. However, it takes a good while (about 3 minute) with the screen flickering to complete the macro. I am assuming this is normal..or is there something I can do to speed it up? Thanks!

  10. #10
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Macro deleting rows based conditional on column data

    Before you start deleting rows add the line:

    Please Login or Register  to view this content.

    and after the delete rows routine add:

    Please Login or Register  to view this content.

    It will be a bit quicker, but won't appear to be doing anything while it works.

    How many of the rows contain the value "TRUE"? If it's not that many then you could speed things up by using a Find to identify them, rather than looping through them iteratively. E.g.

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro deleting rows based conditional on column data

    hi,

    The below link shows a few other approaches for deleting cells which are likely to be faster than looping through a cell at a time.

    http://www.excelforum.com/excel-prog...ts-in-vba.html

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  12. #12
    Registered User
    Join Date
    08-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2000
    Posts
    22

    Re: Macro deleting rows based conditional on column data

    I went to the link you suggested and I think deleting the rows on a filtered request where all of the rows are deleted at once would work well. I have tried to adapt the macro to my situation, but I can't get it to work..I am pretty new at writing macros. Can you help? The column I need to filter is "I". " I" only contains values either "TRUE" of "FALSE". I want to delete all the rows that contain "TRUE" as quickly as possible.

  13. #13
    Registered User
    Join Date
    08-05-2010
    Location
    Texas
    MS-Off Ver
    Excel 2000
    Posts
    22

    Re: Macro deleting rows based conditional on column data

    Andrew...that worked great, I am trying one other way around that was recommended in a later post.to see if I can get it to go any faster. Thanks for your help!

  14. #14
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro deleting rows based conditional on column data

    hi,

    Can you please upload a sample file (preferably with the code which you've attempted to modify)?
    Ensure there is no confidential information in the sample file.

    Thanks
    Rob

+ 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