ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   even (https://www.excelbanter.com/excel-programming/407883-even.html)

ranswert

even
 
How do I find out if a variable is even?
Thanks

Mike H

even
 
Use the MOD function

myvariable = 9
If (myvariable Mod 2) 0 Then
MsgBox "Odd"
Else
MsgBox "Even"
End If

Mike

"ranswert" wrote:

How do I find out if a variable is even?
Thanks


ranswert

even
 
Thanks I'll give that a try.

"Mike H" wrote:

Use the MOD function

myvariable = 9
If (myvariable Mod 2) 0 Then
MsgBox "Odd"
Else
MsgBox "Even"
End If

Mike

"ranswert" wrote:

How do I find out if a variable is even?
Thanks


Rick Rothstein \(MVP - VB\)[_1514_]

even
 
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


"Mike H" wrote in message
...
Use the MOD function

myvariable = 9
If (myvariable Mod 2) 0 Then
MsgBox "Odd"
Else
MsgBox "Even"
End If

Mike

"ranswert" wrote:

How do I find out if a variable is even?
Thanks




All times are GMT +1. The time now is 09:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com