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.

Counting Odds and Evens

by Allen Wyatt
(last updated August 3, 2013)

3

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.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Viewing Multiple Pages

If you have a large monitor, you can view more than one page at a time in Word. This is very handy when you want to ...

Discover More

Jumping to an Endnote

Endnotes are often used in documents to document citations and sources. You can jump from endnote to endnote using the ...

Discover More

Repeating Column Information on Each Page

When your table occupies lots of pages, you may want to have information in a particular column repeated on each page. Word ...

Discover More

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!

MORE EXCELTIPS (RIBBON)

Deleting Duplicate Text Values

Got a list of data from which you want to delete duplicates? There are a couple of techniques you can use to get rid of the ...

Discover More

Relative References within Named Ranges

Excel is usually more flexible in what you can reference in formulas than is immediately apparent. This tip examines some ...

Discover More

Summing Every Fourth Cell in a Row

Need to sum a series of cells that fits some regular pattern? Here are several ways that you can get the summation that you ...

Discover More
Subscribe

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

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 9?

2013-08-06 11:28:24

Bryan

GJCase, it's another way of coercing the true/false into a number. The first negative multiplies by -1 then the second multiplies by -1 again. Yet another reason why I don't like this kind of formula.


2013-08-05 14:12:37

GJCase

Does anyone know why it is necessary to use the double negative on the SUMPRODUCT formulae? I have noticed in the past that these do not work without this, but I've never seen an explanation why this is so.


2013-08-05 07:49:26

Bryan

I always get a little confused with mods and coercions, so I prefer the following two array formulas:

=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.)


This Site

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.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing