Written by Allen Wyatt (last updated June 6, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
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 (7985) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Counting Odds and Evens.
Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!
You can use the Alt+Enter keyboard shortcut while entering information in order to force your data onto multiple lines in ...
Discover MoreWant to sum the values in the same cell on a range of worksheets? It's not as easy as summing a range on the same ...
Discover MoreExcel won't allow you to directly or automatically insert the results of a formula into a cell's comment. You can, ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-06-03 14:11:57
Jon
Hello, I have been trying to find a version of counting the Odd or Even numbers that figures out how many there are between just two numbers.
For example, in my sheet, I have 2 cells right next to each other. The first cell, E6, has the starting number, the second cell, E7, will have the ending number
E6 - 115
E7 - 120
What I am trying to do is find out how many between those numbers are Even when a box is checked, and when another box is checked instead, how many are odd.
Every example and explanation that I have seen always count a full range, like in your example, C2:J2.
Do you know if this formula will be able to calculate that or is there another avenue I should explore?
Thanks
Jon
Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments