where data is the named range B5:B15. The result is 4 since there are four odd numbers in the range B5:B15.

SUMPRODUCT with ISODD

The SUMPRODUCT function works directly with arrays. One thing you can do quite easily with SUMPRODUCT is perform a logical test on a range, then count the results. In this case, we want to count odd numbers, and the simplest way to do that is with the ISODD function. The ISODD function returns TRUE when given an odd number and FALSE when given an even number: In the worksheet shown, the formula in E6 is: Working from the inside out, the logical test is based on the ISODD function: In this case, because data (B5:B15) contains 11 values, the ISODD function returns 11 results in an array like this*:

  • There are a small number of functions in Excel that will not spill when given a range of values. ISODD is one of these functions. The + operator is an easy way to make ISODD return all results. In this array, the TRUE values correspond to cells that contain odd numbers, and the FALSE values represent cells that contain even numbers. To convert the TRUE and FALSE values to 1s and 0s, we use a double negative (–): The resulting array inside the SUMPRODUCT function looks like this: With a single array to process, SUMPRODUCT sums the array and returns 4 as the result.

SUMPRODUCT with MOD

Another way to solve this problem is to use the MOD function like this: Here the logical test for odd numbers looks is this expression: MOD returns a remainder after division. Since, the divisor is 2, MOD will return a remainder of 1 for any odd integer, and a remainder of zero for an even integer. We therefore test for 1. Since there are 11 values in data (B5:B15), the result is an array of 11 TRUE / FALSE values: To convert the TRUE and FALSE values to 1s and 0s, we use a double negative (–): The resulting array inside the SUMPRODUCT function looks like this: With a single array to process, SUMPRODUCT sums the array and returns 4 as the result.

Counting even numbers

As you might guess, you can count even numbers in a range by making small adjustments to the formulas above. To adapt the ISODD version of the formula to count even numbers, simply replace the ISODD function with the ISEVEN function like this: To adapt the MOD function version of the formula, adjust the logic to check for zero instead of 1: The behavior of these formulas is the same as described previously, and both formulas return 7, since the range B5:B15 contains 7 even numbers.

Dave Bruns

Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.