count if odd or even

What formula should i use to count the number of cells that are odd, or even?

MacBook Pro (Retina, 13-inch, Late 2013), OS X Yosemite (10.10.2)

Posted on Mar 15, 2015 7:18 AM

Reply
10 replies

Mar 15, 2015 4:49 PM in response to FePerrella

Hello FePerrella,


This is one way:


User uploaded file

This solution requires an auxiliary column. In this case, the data is in B and column A is the auxiliary column. You can pick any columns and adjust the expressions. Then you may hide the auxiliary column if you wish.


The expression in Column A is:


=IF(MOD(B, 2)=0, "EVEN", "ODD")


The expression for counting odd results is: =COUNTIF(A, "ODD")


and, the expression for counting even results is: =COUNTIF(A, "EVEN")


I am not aware of any way, short of a script, to both calculate the evenness or oddness of each entry and do the count in one cell.


Jerry

Mar 15, 2015 6:16 PM in response to Jerrold Green1

Hi Jerold, thanks for the help.


I want to count just one of then, for example ODD, i have a table like this one.


ODD Count

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O


04

12

21

22

02

11

24

25

01

10

14

17

08

13

23


It won't be easy to add the IF column to count the ODDs, because i have a lot of lines, but fixed columns, it wouldn't work for me if i transpose the table also.

Do you think there is other solution?

I found in Excel and Google Spreadsheet the sumproduct but couldn't make it work also...

Mar 16, 2015 7:33 AM in response to FePerrella

Hi FP,


However i don't want to create a new line for each IF sentence.


Try this. Create another table ('Odds') to test is a value is odd.

User uploaded file

Formula in B2 of the Odds table (and Fill Right and Down)

=ISODD(Table 1::B2)


I added Conditional Highlighting to the Odds table to show green for TRUE. You can move the Odds table to another Sheet to 'hide' it if you want.


Formula in A2 of Table 1 (and Fill Down)

=COUNTIF(Odds::2:2,"TRUE")

User uploaded file


Regards,

Ian.

Mar 16, 2015 7:47 AM in response to FePerrella

Hello


Obviously you may calculate sum of MOD(n,2) for given numbers. Formula would become lengthy, though.


E.g.,


User uploaded file



Table 1 (excerpt) A2 =MOD(B2,2)+MOD(C2,2)+MOD(D2,2)+MOD(E2,2)+MOD(F2,2) +MOD(G2,2)+MOD(H2,2)+MOD(I2,2)+MOD(J2,2)+MOD(K2,2) +MOD(L2,2)+MOD(M2,2)+MOD(N2,2)+MOD(O2,2)+MOD(P2,2) B2 =RANDBETWEEN(0,50) C2 =RANDBETWEEN(0,50) D2 =RANDBETWEEN(0,50) E2 =RANDBETWEEN(0,50) F2 =RANDBETWEEN(0,50) G2 =RANDBETWEEN(0,50) H2 =RANDBETWEEN(0,50) I2 =RANDBETWEEN(0,50) J2 =RANDBETWEEN(0,50) K2 =RANDBETWEEN(0,50) L2 =RANDBETWEEN(0,50) M2 =RANDBETWEEN(0,50) N2 =RANDBETWEEN(0,50) O2 =RANDBETWEEN(0,50) P2 =RANDBETWEEN(0,50)




Or you may introduce auxiliary columns to store MOD(n,2) for given numbers. Formula would be concise and easily filled.


E.g.,


User uploaded file



Table 2 (excerpt) A2 =SUM(Q2:AE2) B2 =RANDBETWEEN(0,50) C2 =RANDBETWEEN(0,50) D2 =RANDBETWEEN(0,50) E2 =RANDBETWEEN(0,50) F2 =RANDBETWEEN(0,50) G2 =RANDBETWEEN(0,50) H2 =RANDBETWEEN(0,50) I2 =RANDBETWEEN(0,50) J2 =RANDBETWEEN(0,50) K2 =RANDBETWEEN(0,50) L2 =RANDBETWEEN(0,50) M2 =RANDBETWEEN(0,50) N2 =RANDBETWEEN(0,50) O2 =RANDBETWEEN(0,50) P2 =RANDBETWEEN(0,50) Q2 =MOD(B2,2) R2 =MOD(C2,2) S2 =MOD(D2,2) T2 =MOD(E2,2) U2 =MOD(F2,2) V2 =MOD(G2,2) W2 =MOD(H2,2) X2 =MOD(I2,2) Y2 =MOD(J2,2) Z2 =MOD(K2,2) AA2 =MOD(L2,2) AB2 =MOD(M2,2) AC2 =MOD(N2,2) AD2 =MOD(O2,2) AE2 =MOD(P2,2)



Regards,

H

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

count if odd or even

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.