Thread: sum odd numbers
View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.misc
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default sum odd numbers

Thank you all for your help. I dont really understand the MOD() formula

The MOD function returns the remainder after division. So, for this...

=MOD(17,5)

look at the division 17/5, the answer is 3 with a remainder of 2. The above
formula returns the remainder, in this case, 2. Now, for odd numbers, when
divided by 2, they always have a remainder of 1. So, the expression
MOD(SomeNumber,2) will evaluate to 1 whenever SomeNumber is odd. Also, an
even number always has a remainder of 0 (2 always divides even numbers
evenly, sort of by definition). So MOD(SomeNumber,2) will evaluate to 0
whenever SomeNumber is even. The SUMPRODUCT formula that Bernd posted makes
use of this to multiply the odd numbers by their return value of 1 and the
even numbers by their return value of 0, thus resulting in the addition of
only the odd numbers.

Rick