+ Reply to Thread
Results 1 to 2 of 2

forgotten variations of loop

  1. #1
    Registered User
    Join Date
    03-02-2006
    Posts
    54

    forgotten variations of loop

    Hi i have always used the following loop statement in my code.
    Do
    ''stuff
    '' have a range setup
    set rng = rng.offset(1,0)

    Loop until rng = (some value such as 2004)

    I know that somehow you can loop until you find a certain value e.g 2003, perform the loop once more and then exit loop. This would avoid using the 'until' part and would benefit me more as not all of my sheets contain cells with 2004 in them.

    Just to give you a bit further background the loop copies and pastes raw data in certain columns until it reaches 2004 which is forecasted, however not all sheets/ranges need to contain forecasted data and thus have a column entitled 2004!!

  2. #2
    Tom Ogilvy
    Guest

    RE: forgotten variations of loop

    You can condition on the current cell at the top of the loop so that all 2003
    gets processed and it quits before it processes 2004

    Do while rng < 2004
    set rng = rng.offset(1,0)
    Loop

    However, your original code would also perform that way. The next cell to
    be processed is checked at the bottom of the loop, so if that were 2004 it
    would quit.


    Perhaps you could be more specific about this particular situation and what
    you want to do.
    --
    Regards,
    Tom Ogilvy



    "cereldine" wrote:

    >
    > Hi i have always used the following loop statement in my code.
    > Do
    > ''stuff
    > '' have a range setup
    > set rng = rng.offset(1,0)
    >
    > Loop until rng = (some value such as 2004)
    >
    > I know that somehow you can loop until you find a certain value e.g
    > 2003, perform the loop once more and then exit loop. This would avoid
    > using the 'until' part and would benefit me more as not all of my
    > sheets contain cells with 2004 in them.
    >
    > Just to give you a bit further background the loop copies and pastes
    > raw data in certain columns until it reaches 2004 which is forecasted,
    > however not all sheets/ranges need to contain forecasted data and thus
    > have a column entitled 2004!!
    >
    >
    > --
    > cereldine
    > ------------------------------------------------------------------------
    > cereldine's Profile: http://www.excelforum.com/member.php...o&userid=32069
    > View this thread: http://www.excelforum.com/showthread...hreadid=543676
    >
    >


+ 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