Thread: even numbers
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Kevin Kevin is offline
external usenet poster
 
Posts: 4
Default even numbers

Use the Mod operator.

dim EvenOdd as string

if(x mod y =0)then
EvenOdd="Even"
else
EvenOdd="Odd"
End If

The mod operator divides two numbers and returns the
remainder. If the remainder is 0 it is even.

Hope that helps!

Kevin
-----Original Message-----

"Tommi" wrote in message
...
How to check in VBA code if number is even (or odd)?


Think of a number, divide it by 2, take the integer part,

and multiply that
by 2. Then take away the number you first thought of. If

you are left with
nothing then the number you started with was even.

HTH
Geoff




.