For Next non-sequential numbers

R

ragtopcaddy via AccessMonster.com

Isn't there some loop that allows non-sequential numbers? I thought I had
come across or actually used something like:

For n = 0 to 4, 6 to 10

Next n

Any suggestions?
 
S

Stefan Hoffmann

hi Bill,
Isn't there some loop that allows non-sequential numbers?
No. Why would you do that?

Under some circumstance you may consider using a mapping array, e.g.

Dim arr() As Long
Dim i As Long
Dim n As Long

ReDim arr(0 To 7) As Long

arr(0) = 1
arr(1) = 2
arr(2) = 3
arr(3) = 4
arr(4) = 6
arr(5) = 8
arr(6) = 9
arr(7) = 10

For i = LBound(arr()) To UBound(arr())
n = arr(i)
'...
Next i


mfG
--> stefan <--
 
P

Paolo

Hi Bill,
I dunno if exist a loop of the kind you said but you can do that

for n=0 to 10
your code
if n=4 then
n=5 'placing five in n before the next n statement allow you to
skip this value 'cause the next n add 1 to n and so n will be 6
endif
next n

HTH Paolo
 
R

ragtopcaddy via AccessMonster.com

Thanks to all for your suggestions. I'm going with Paolo's as it's the
simplest.
The reason I'd like to do something like this is for simplicity. I'd prefer
to avoid arrays and custom functions unless absolutely necessary.

Thanks,

Hi Bill,
I dunno if exist a loop of the kind you said but you can do that

for n=0 to 10
your code
if n=4 then
n=5 'placing five in n before the next n statement allow you to
skip this value 'cause the next n add 1 to n and so n will be 6
endif
next n

HTH Paolo
Isn't there some loop that allows non-sequential numbers? I thought I had
come across or actually used something like:
[quoted text clipped - 4 lines]
Any suggestions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top