View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.worksheet.functions
T. Valko T. Valko is offline
external usenet poster
 
Posts: 15,768
Default Countif function for Even and Odd numbers

version for the "odd" formula should be
=sumproduct (--(ISNUMBER(A1:A10)),--(A1:A10-2*INT(A:A10/2)=1))


You don't need the ISNUMBER test. An empty cell evaluates to 0. On an empty
cell this portion will *always* evaluate to 0:

cell_ref-2*INT(cell_ref/2)

So:

0=1 will be FALSE and therefore not counted.

=SUMPRODUCT(--(A1:A10-2*INT(A1:A10/2)=1))


--
Biff
Microsoft Excel MVP


"Jezzy" wrote in message
...
Hi T. Valko,

Thanks! The version you showed below works. So, if I were to use your
version for the "odd" formula should be

=sumproduct (--(ISNUMBER(A1:A10)),--(A1:A10-2*INT(A:A10/2)=1))

I didn't realize that there are so many ways of setting arguments in a
formula. Although the method shown by MartinW is much easier (less
input), I
guess it doesn't hurt to learn more ways.

Thanks alot guys!

Jez



"T. Valko" wrote:

It's counting empty cells.

Here are my thoughts on this. Based on the limited sample you posted it
looks like you're dealing with integers. While Harlan is correct on the
points he made I think it's a bit of overkill if:

....the numbers you're dealing with are *always* integers
....the numbers are *always* less than ~200,000,000

Try this version of Harlan's formula:

=SUMPRODUCT(--(ISNUMBER(A1:A10)),--(A1:A10-2*INT(A1:A10/2)=0))

--
Biff
Microsoft Excel MVP


"Jezzy" wrote in message
...
Hi MartinW and Harlan,

I tried the method by Harlan Grove. When filling in the formula for
"odd"
it's fine. When I input the formula for "even" it seems a little weird
because after I cleared all the numbers in the column, under the "odd"
formula cell it's gives me a "zero" which is correct but under the
"even"
formula cell it came out the number "9" when there was nothing to
count.
My
table consists of 9 rows of numbers in every column.

Maybe he can explain where the error lies.

Thanks.

Jez

"MartinW" wrote:

Hi Jez,

That's not my method, it's one I saved from a post a couple
of years ago. It may have been Biff's although I think more
likely it was Bob Phillips. You may also want to take note
of Harlan Grove's comments on the use of MOD and INT.

Anyway, all up it sounds like you found what you were
looking for so that's the main thing.

Cheers
Martin


"Jezzy" wrote in message
...
Hi All,

Thanks for the reply. I tried MartinW's method and it works.
Appreciate
all your help very much.


Jez

"MartinW" wrote:

Hi,

Saved from a previous post,

This will count the EVENS
=SUMPRODUCT(--(A1:A10<""),--(MOD(A1:A10,2)=0))

And this the ODDS
=SUMPRODUCT(--(A1:A10<""),--(MOD(A1:A10,2)=1))

HTH
Martin


"Jezzy" wrote in message
...
Hi Hi,

I need help with a formula. I would like to count a column that
consists
of
even and odd numbers eg. 28, 31, 43, 50, 60. I like to count
how
many
numbers in that column is odd or even.

I have tried the following but it didn't work

=countif(a1:a10,"1","3","5")

Appreciate some help here.

Thanks