**Please Note: **
This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), *this tip may not work for you*. For a version of this tip written specifically for earlier versions of Excel, click here: Counting Odds and Evens.

Pini has a range of whole numbers (let's say C2:J2) and some of the numbers can be odd and some even. He would like a formula to count the number of odd values in the range and another to count the number of even values in the range.

There are a couple of ways to derive the desired counts, without resorting to intermediate values or macros. One way is to use an array formula, such as the following, to determine a count of odd values:

=SUM((MOD(C2:J2,2)<>0)*1)

Enter the formula using **Ctrl+Shift+Enter** and you get the desired count. Only a small change is required for the array formula to return the count of even numbers:

=SUM((MOD(C2:J2,2)=0)*1)

If you prefer to not use an array formula, you could use SUMPRODUCT to return the same count, as a regular formula. For example, here is the formula to return a count of odd values:

=SUMPRODUCT(--(MOD(C2:J2,2)=1),--(C2:J2<>""))

This is the formula for even values:

=SUMPRODUCT(--(MOD(C2:J2,2)=0),--(C2:J2<>""))

Another advantage of using the SUMPRODUCT approach is that it compensates for possible blank cells in your range. The earlier array formulas will always count blank cells as if they contain an even value.

*ExcelTips* is your source for cost-effective Microsoft Excel training.
This tip (7987) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: **Counting Odds and Evens**.

**Save Time and Supercharge Excel!** Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out *Excel 2010 VBA and Macros* today!

You can use the Alt+Enter keyboard shortcut while entering information in order to force your data onto multiple lines in a ...

Discover MoreWhen working with financial data, it's easy to round values to the nearest dollar. What if you want them rounded to the ...

Discover MoreSumming data is a common need in Excel. Summing lots of data based on a condition that needs to be met can be a bit more ...

Discover More**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

2017-08-09 13:02:53

Dave Bonin

I understand your dislike of the SUMPRODUCT() function; it has some quirks.

Unfortunately, the average, everyday user of Excel is not familiar with array formulae,

much less the Ctrl+Shift+Enter sequence used to complete an array formula.

This leads to issues when users "examine" a formula and then inadvertently re-enter

the formula without the Ctrl+Shift+Enter sequence. The newly-non-array formula

no longer produces the desired result and computational pandemonium ensues.

The SUMPRODUCT() function, acts like an array formula, but has no special entry

syntax. That makes them much safer for use around typical users.

In my humble opinion, Microsoft did a disservice to users when it introduced and

required the special array formula entry sequence, especially while doing nothing

much further to aid the user to identify an array formula. The brackets, while

helpful, are insufficient.

While working with array formulae, it's very easy to forget to Ctrl+Shift+Enter.

I've done it countless times and I suspect you have, too. If we're really good

with Excel and we mess up, imagine how much harder it is for more average

users.

2017-08-09 12:39:46

Neil

=SUMPRODUCT(ISODD(C2:J2*1)*1)

=SUMPRODUCT(ISEVEN(C2:J2*1)*1)

=SUMPRODUCT(--ISODD(--C2:J2))

=SUMPRODUCT(--ISEVEN(--C2:J2))

And some that don't count blanks as even:

=SUMPRODUCT(ISEVEN(A2:A22*1)*1, (A2:A22<>"")*1)

=SUMPRODUCT(--ISEVEN(--A2:A22), --(A2:A22<>""))

2013-08-06 11:28:24

Bryan

2013-08-05 14:12:37

GJCase

2013-08-05 07:49:26

Bryan

=SUM(IF(ODD(C2:J2)=C2:J2,1,0))

=SUM(IF(EVEN(C2:J2)=C2:J2,1,0))

The odd form will count blanks correctly, but the even form will count them as even numbers (0).

These formulas are a little simpler to understand, but for some reason there's an extra coercion... ISODD/ISEVEN won't work like you expect them to in an array formula:

=SUM(ISODD(C2:J2*1)*1)

=SUM(ISEVEN(C2:J2*1)*1)

(For those who don't know, multiplying a true/false by 1 lets you add them together as if they were numbers. True*1=1, False*1 = 0. This is called coercion, as you are coercing the true/false to be numbers.)

Got a version of Excel that uses the
ribbon interface (Excel 2007 or later)?
**This site is for you!** If you
use an earlier version of Excel, visit
our *ExcelTips* site focusing on the menu interface.

**FREE SERVICE:** Get tips like this every week in *ExcelTips,* a free productivity newsletter. Enter your address and click "Subscribe."

Copyright © 2017 Sharon Parq Associates, Inc.

## Comments