PDA

View Full Version : How to classify different rows to same group



helai
03-13-2006, 12:29 AM
I have code with"for next "sentence embeded,and I want classify the row with 2,4,6,8,10...to one group,and with 1,3,5,7,9..to another group,and I use the formula vartype(i/2)=2,but even the i=1 or i=2 ,the vartype(i/2)always equal=5
who canhelp me to identy the different rows selected ,which formula is appropriate


Private Sub CommandButton3_Click()
For i = 1 To 500
m = VarType(i / 2)
Next i
End Sub


any suggestion is welcome
helai

smc2911
03-13-2006, 03:31 AM
VarType always returns 5 because this function returns the data type of the argument. In this case i/2 is of type Double so VarType returns the value 5 which corresponds to the constant vbDouble.

To achieve what you are after, I suggest using i Mod 2 which will return a value 0 for i=0,2,4,6,... and 1 for i=1,3,5,7,...

Sean.

mdmackillop
03-13-2006, 12:53 PM
Hi Helai
You could possibly use
For i = 1 to 500 Step 2, For i = 2 to 500 Step 2
Depends what you're doing.
Regards
MD

helai
03-13-2006, 05:26 PM
now is ok
thank you again