ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   For..Next Question (https://www.excelbanter.com/excel-programming/358325-next-question.html)

Sandy

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


Scoops

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


Scoops

For..Next Question
 
Hi Sandy

Probably better is:

If i < 5 Or i 7 Then...

Regards

Steve


Dave Peterson

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

Bob Phillips[_6_]

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




Tom Ogilvy

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



Jesse[_7_]

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


vikas.bhandari

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


Tom Ogilvy

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




All times are GMT +1. The time now is 12:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com