M Mike H Mar 18, 2008 #2 Use the MOD function myvariable = 9 If (myvariable Mod 2) > 0 Then MsgBox "Odd" Else MsgBox "Even" End If Mike
Use the MOD function myvariable = 9 If (myvariable Mod 2) > 0 Then MsgBox "Odd" Else MsgBox "Even" End If Mike
R ranswert Mar 18, 2008 #3 Thanks I'll give that a try. Mike H said: Use the MOD function myvariable = 9 If (myvariable Mod 2) > 0 Then MsgBox "Odd" Else MsgBox "Even" End If Mike Click to expand...
Thanks I'll give that a try. Mike H said: Use the MOD function myvariable = 9 If (myvariable Mod 2) > 0 Then MsgBox "Odd" Else MsgBox "Even" End If Mike Click to expand...
D Dana DeLouis Mar 18, 2008 #4 How do I find out if a variable is even? Just make sure you are working with Integers since vba's MOD rounds the input. Sub xxx() Dim n n = 9.5 'Considered Even If (n Mod 2) > 0 Then MsgBox "Odd" Else MsgBox "Even" End If 'Odd MsgBox WorksheetFunction.IsOdd(9.999999999) 'Even MsgBox WorksheetFunction.IsOdd(9.9999999999) End Sub
How do I find out if a variable is even? Just make sure you are working with Integers since vba's MOD rounds the input. Sub xxx() Dim n n = 9.5 'Considered Even If (n Mod 2) > 0 Then MsgBox "Odd" Else MsgBox "Even" End If 'Odd MsgBox WorksheetFunction.IsOdd(9.999999999) 'Even MsgBox WorksheetFunction.IsOdd(9.9999999999) End Sub
R Rick Rothstein \(MVP - VB\) Mar 19, 2008 #5 You can also do it this way (execution should be marginally faster)... MyVariable = 9 If MyVariable And 1 Then MsgBox "Odd" Else MsgBox "Even" End If Rick
You can also do it this way (execution should be marginally faster)... MyVariable = 9 If MyVariable And 1 Then MsgBox "Odd" Else MsgBox "Even" End If Rick