+ Reply to Thread
Results 1 to 9 of 9

For..Next Question

  1. #1
    Sandy
    Guest

    For..Next Question

    I was wondering if the was a way to skip numbers in a counting
    sequence. For example:

    For i = 1 to 10
    next i

    Is there a way to skip over 5, 6, 7 so the count could be

    1, 2, 3, 4, 8, 9, 10?

    Thanks in advance.

    Sandy


  2. #2
    Scoops
    Guest

    Re: For..Next Question

    Hi Sandy

    Try this:

    For i = 1 to 10
    If i <> 5 Or i <> 6 Or i <> 7 Then
    yourprocedure
    End if
    Next

    Regards

    Steve


  3. #3
    Scoops
    Guest

    Re: For..Next Question

    Hi Sandy

    Probably better is:

    If i < 5 Or i > 7 Then...

    Regards

    Steve


  4. #4
    Dave Peterson
    Guest

    Re: For..Next Question

    Just check?

    For i = 1 to 10
    select case i
    case 5,6,7
    'do nothing
    case else
    'do what you want
    end select
    next i

    Sandy wrote:
    >
    > I was wondering if the was a way to skip numbers in a counting
    > sequence. For example:
    >
    > For i = 1 to 10
    > next i
    >
    > Is there a way to skip over 5, 6, 7 so the count could be
    >
    > 1, 2, 3, 4, 8, 9, 10?
    >
    > Thanks in advance.
    >
    > Sandy


    --

    Dave Peterson

  5. #5
    Bob Phillips
    Guest

    Re: For..Next Question

    Many ways, such as

    For i = 1 to 10
    If i > 4 And i < 8 Then
    ... your bits
    End If
    next i

    or

    For i = 1 to 10
    ... your bits
    If i = 4 Then i = 7
    Next i

    and many others I am sure


    --
    HTH

    Bob Phillips

    (remove nothere from email address if mailing direct)

    "Sandy" <[email protected]> wrote in message
    news:[email protected]...
    > I was wondering if the was a way to skip numbers in a counting
    > sequence. For example:
    >
    > For i = 1 to 10
    > next i
    >
    > Is there a way to skip over 5, 6, 7 so the count could be
    >
    > 1, 2, 3, 4, 8, 9, 10?
    >
    > Thanks in advance.
    >
    > Sandy
    >




  6. #6
    Tom Ogilvy
    Guest

    RE: For..Next Question

    for i = 1 to 10
    if i < 5 or i > 7 then

    end if
    Next

    --
    Regards,
    Tom Ogilvy


    "Sandy" wrote:

    > I was wondering if the was a way to skip numbers in a counting
    > sequence. For example:
    >
    > For i = 1 to 10
    > next i
    >
    > Is there a way to skip over 5, 6, 7 so the count could be
    >
    > 1, 2, 3, 4, 8, 9, 10?
    >
    > Thanks in advance.
    >
    > Sandy
    >
    >


  7. #7
    Jesse
    Guest

    Re: For..Next Question

    Since i is a variable couldn't you...

    For i = 1 to 10

    if i=4 then i=7

    Next i


    Jesse


  8. #8
    Forum Contributor vikas.bhandari's Avatar
    Join Date
    04-07-2006
    Location
    Delhi, India
    MS-Off Ver
    Office 2007 and 2010
    Posts
    303
    well..a simple code, so many answers..Jesse Wins :o)

    Cheers.....

  9. #9
    Tom Ogilvy
    Guest

    Re: For..Next Question

    Most consider it bad form to change the index variable within a loop.

    --
    Regards,
    Tom Ogilvy


    "vikas.bhandari" wrote:

    >
    > well..a simple code, so many answers..Jesse Wins :o)
    >
    > Cheers.....
    >
    >
    > --
    > vikas.bhandari
    > ------------------------------------------------------------------------
    > vikas.bhandari's Profile: http://www.excelforum.com/member.php...o&userid=33276
    > View this thread: http://www.excelforum.com/showthread...hreadid=530938
    >
    >


+ 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