Evaluating Numbers in a Sequenced Step Count

G

Greg Maxey

I have an undetermined number that I need to sequence and do one thing if
the number is:

0, 4, 8, 12

Something else for:

1, 5, 9, 13

Something else for"

2, 6, 10, 14 ...

and finally something else for:

3, 7, 11, 15 ...

I can do that for a limited sized number using Select Case as shown below,
but I don't know how large "i" needs to be. How else could I evaluate i as
it is indexed to see which step count it belongs to? Thanks.

Sub ScratchMacro()
Dim i As Long
For i = 0 To 35
Select Case i
Case 0, 4, 8, 12, 16, 20, 24, 28, 32
MsgBox "Do A"
Case 1, 5, 9, 13, 17, 21, 25, 29, 33
MsgBox "Do B"
Case 2, 6, 10, 14, 18, 22, 26, 30, 34
MsgBox "Do C"
Case 3, 7, 11, 15, 19, 23, 27, 31, 35
MsgBox "Do D"
Case Else
'Do Nothing
End Select
Next i
End Sub


--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 
J

Jay Freedman

Hi Greg,

The Mod function divides one number by another number and returns the remainder.
In your case you want to divide your step number by 4 and see whether the
remainder is 0, 1, 2, or 3 (the only possible remainders):

Sub x()
Dim i As Long
For i = 0 To 35 ' or whatever
Select Case i Mod 4
Case 0
MsgBox "Do A"
Case 1
MsgBox "Do B"
Case 2
MsgBox "Do C"
Case 3
MsgBox "Do D"
Case Else
'Do Nothing -- should never happen!
End Select
Next i
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
G

Greg Maxey

Jay,

Yes, perfect. I have seen MOD used before but it was one of those that
slipped my memory.

Thanks.


Jay said:
Hi Greg,

The Mod function divides one number by another number and returns the
remainder. In your case you want to divide your step number by 4 and
see whether the remainder is 0, 1, 2, or 3 (the only possible
remainders):

Sub x()
Dim i As Long
For i = 0 To 35 ' or whatever
Select Case i Mod 4
Case 0
MsgBox "Do A"
Case 1
MsgBox "Do B"
Case 2
MsgBox "Do C"
Case 3
MsgBox "Do D"
Case Else
'Do Nothing -- should never happen!
End Select
Next i
End Sub

--
Greg Maxey - Word MVP

My web site http://gregmaxey.mvps.org


McCain/Palin '08 !!!
 

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