Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default For..Next Question

Hi Sandy

Probably better is:

If i < 5 Or i 7 Then...

Regards

Steve

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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" wrote in message
ups.com...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For..Next Question


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

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 05:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"