+ Reply to Thread
Results 1 to 8 of 8

How do i loop prematurely?

  1. #1
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    How do i loop prematurely?

    I have a loop that if a condition is met I need it to loop early. How is that possible?

    Here is the code:

    Please Login or Register  to view this content.
    I cannot use an else on the if statement for this purpose because I have other ifs that are needed. for different purposes.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: How do i loop prematurely?

    Hello there,

    Try this:

    Please Login or Register  to view this content.

  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: How do i loop prematurely?

    Hi,

    I'm a fan of the For...Next loop but there are others that I think you are needing here. The list of loop types are at: http://www.anthony-vba.kefra.com/vba/vbabasic3.htm
    Perhaps you need a Do While construct to accomplish your "premature" loop.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: How do i loop prematurely?

    rvasquez,

    Thank you for your help but I have too much other code that I cannot use the elseif.

    Marvin,

    I use For Next very often but I don't think it can be used in this situation. Also a Do While loop will not give me a premature loop it will stop when the condition is met (at least that is how I understand it)

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: How do i loop prematurely?

    Hi djblois1
    Have you considered a "GoTo" statement
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How do i loop prematurely?

    Please give an example.
    I don't see your 'problem'.



  7. #7
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: How do i loop prematurely?

    Could you post your entire code?

  8. #8
    Forum Contributor
    Join Date
    08-23-2010
    Location
    Staten Island, NY
    MS-Off Ver
    Excel 2003
    Posts
    242

    Re: How do i loop prematurely?

    Jaslake that is what I do now, I use a goto statement. I was wondering if there was a more elegant way to do this. I am pretty positive there is a way to do it in more advanced programming languages.

+ 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