+ Reply to Thread
Results 1 to 9 of 9

Looping problem

  1. #1
    Registered User
    Join Date
    10-16-2012
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    3

    Looping problem

    Hi

    I have the following code
    HTML Code: 
    which is supposed to look in column a for a date, if appropriate date is found it is supposed to copy that row and paste it into a seperate sheet.

    This works fine to a point but once its found two or three occurances it stops looking and I have to run the macro again.

    Any ideas why it doesn't keep looping until it finds all the occurances.

    Any help appreciated

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Looping problem

    May be change this line
    Please Login or Register  to view this content.
    In to
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Looping problem

    As a general rule, any loop that looks like this:
    for x = 1 to
    rows(x).delete
    next
    is going to have problems as the area covered gets smaller.

    One approach is to use
    for x = finalrow to 1 step -1
    and work from the bottom up.

    OR if you must move down, use do While...loop and control the exit condition yourself.
    Last edited by brynbaker; 11-07-2012 at 04:00 AM.

  4. #4
    Registered User
    Join Date
    08-19-2011
    Location
    Norwich, England
    MS-Off Ver
    Excel 2007
    Posts
    56

    Re: Looping problem

    Hiya,

    I'm not sure about the line:

    Please Login or Register  to view this content.
    Is this doing what you want? It'll start at A55, then A56 etc. So any rows that match your criteria that are higher than row 55 won't be caught?

    HTH

    S.

  5. #5
    Registered User
    Join Date
    10-16-2012
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    3

    Re: Looping problem

    Thanks brynbaker
    Works a treat now by would never have got that myself

  6. #6
    Registered User
    Join Date
    10-16-2012
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    3

    Re: Looping problem

    Thank OnlySteveH

    That was a typo on my part. Would have driven me mad later

  7. #7
    Forum Contributor
    Join Date
    08-23-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    163

    Re: Looping problem

    Need to adjust the counter after deleting row....I think below code work
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-18-2012
    Location
    Telford, England
    MS-Off Ver
    Excel 2010 (2003)
    Posts
    294

    Re: Looping problem

    I had that bug in my code, so I'm happy to help. It is far from obvious.

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Looping problem

    @ plycc100no

    Welcome to the forum.

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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