# Math syntax I'm having trouble with...

## Recommended Posts

I was a math major long ago, but I'm drawing a blank on this one. I suspect someone else can figure this out in less than a minute. I have a For/Next loop that goes from 1 to 500. I need to be able to tell which group x falls in (see graphic for the two groups). Here's what I want the code to say, but I don't know how to word the If x is in Group 1 Then and the ElseIf x is in Group 2. I realize I probably don't need the ElseIf, i.e., it could probably just be a plain Else.

```For x = 1 to 500
If x is in Group 1 Then
do something here
ElseIf x is in Group 2 Then
do something here
EndIf
Next```

Here are the groups:

Thank you.

##### Share on other sites

Some logic to identify Group1 and Group2:

```For \$x = 1 to 500
If (\$x/16) - Int(\$x/16) = 0 Then
\$group = 2
ElseIf (\$x/16) - Int(\$x/16) < .51 Then
\$group = 1
Else
\$group = 2
EndIf
MsgBox(262144,'Debug',"x=" & \$x & "  \$group=" & \$group);### Debug MSGBOX
Next```

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

I was a math major long ago, but I'm drawing a blank on this one.   I suspect someone else can figure this out in less than a minute.  I have a For/Next loop that goes from 1 to 500.  I need to be able to tell which group x falls in (see graphic for the two groups).  Here's what I want the code to say, but I don't know how to word the If x is in Group 1 Then and the ElseIf x is in Group 2.  I realize I probably don't need the ElseIf, i.e., it could probably just be a plain Else.

```For x = 1 to 500
If x is in Group 1 Then
do something here
ElseIf x is in Group 2 Then
do something here
EndIf
Next```

<{POST_SNAPBACK}>

The Mod function.

```For \$x = 0 To 33
\$iRem = Mod(\$x, 16)
If \$iRem > 0 And \$iRem < 9 Then
MsgBox(4096, "Group1", \$X & " = Group1", 1)
Else
MsgBox(4096, "Group2", \$X & " = Group2", 1)
EndIf
Next```

Phillip

##### Share on other sites

Thank you for your help, both of you.

## Create an account

Register a new account