odd or even numbers

F

Fred Kruger

Is there an easy way of checking when a value is entered in a inputbox whther
the value is a even number or a odd number. only whole numbers will be
entered as i want to then due certain things if even numbers and different
things if the number is odd.

Cheers in anticipation
 
K

Klaus Linke

Hi Fred,

Look in the VBA help for "operators".
x\2 gives you the same as x/2, but without the decimal part (= the "rest").

Another way would be by means of the mod operator:
If x mod 2 = 0 then ' ... it's even
(and x mod 2 = 1 for odd positive integers, -1 for odd negative integers)

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top