#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default even

How do I find out if a variable is even?
Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 161
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:06 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"