+ Reply to Thread
Results 1 to 4 of 4

Macro needs to be run many times to catch all occurrences

  1. #1
    Registered User
    Join Date
    09-27-2012
    Location
    Wisconsin
    MS-Off Ver
    Excel 2000
    Posts
    14

    Macro needs to be run many times to catch all occurrences

    I wrote a little macro to go through a list and delete rows containing certain criteria. It works ok, but I have to run it many times for it to catch them all. Please help me determine where I went wrong.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Macro needs to be run many times to catch all occurrences

    If you delete rows, it's better to work backwards - also, make sure you put it in a module and not as worksheet code.
    Try this :

    Please Login or Register  to view this content.
    Please click the * below if this helps

  3. #3
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Macro needs to be run many times to catch all occurrences

    When you delete a row, you skip the next cell as it becomes the previous cell the loop has already looked at. Easiest way around this is to work through the range from top to bottom:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    09-27-2012
    Location
    Wisconsin
    MS-Off Ver
    Excel 2000
    Posts
    14

    Re: Macro needs to be run many times to catch all occurrences

    Well explained, yudlugar. Lesson learned. Thank you very much guys!

+ 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