+ Reply to Thread
Results 1 to 3 of 3

Do While Macro seems to work in stages

  1. #1
    Registered User
    Join Date
    10-07-2008
    Location
    Felixstowe
    Posts
    4

    Do While Macro seems to work in stages

    Afternoon all

    I have a macro which loops through data, deleting those rows that are marked with a "Y".

    However - it appears to always want to do this in three stages. The first time I run the macro, it delete's a large chunk of those marked rows - but it nearly always leaves two rows. The second time I run it, it deletes one of those two remaining rows. And then I run it again and it deletes the final outstanding row.

    I'm sure i've done something stupid here - the code is below, please can somebody take a look and tell me what I've done wrong !


    Please Login or Register  to view this content.
    End Sub
    Last edited by walneyhammer; 06-02-2009 at 09:58 AM. Reason: Solved

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Do While Macro seems to work in stages

    when deleting rows you need to start at the bottom and work up.
    Or adjust your indexing variable to it does not increment when deleting a row.

    Basically you index variable will get out of sync. Say it is pointing to row 6, you delete that row so now row 7 is actually row 6. You increment the indexer to 7 and do not check the new row 6. So in order to check it you run the code again.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-07-2008
    Location
    Felixstowe
    Posts
    4

    Re: Do While Macro seems to work in stages

    So simple and yet I couldn't see it !

    This works perfectly, I just added the code

    Please Login or Register  to view this content.
    within the IF statement in my loop, and therefore whenever a row was deleted the incremental was set back to the correct place

    Many thanks for you help

+ 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