Summary

To count the number of cells that contain positive numbers in a range, you can use the COUNTIF function. In the example shown, cell E6 contains this formula:

=COUNTIF(data,">0")

Where data is the named range B5:B15. The formula returns 7, since seven cells in B5:B15 contain numbers greater than zero.

Generic formula

=COUNTIF(rng,">0")

Explanation 

In this example, the goal is to count the number of cells in a range that contain positive numbers. For convenience, the range B5:B15 is named data. This problem can be solved with the COUNTIF function or the SUMPRODUCT function. Both methods are explained below.

COUNTIF function

The COUNT function counts the number of cells in a range that meet supplied criteria. For example, you can use COUNTIF like this:

=COUNTIF(range,"red") // count cells equal to "red"
=COUNTIF(range,100) // count cells equal to 100
=COUNTIF(range,">10") // count cells greater than 10

To count positive numbers in this example, we need to use the "greater than" operator (>) together with a zero like this:

=COUNTIF(data,">0") // returns 7

The result is 7, since seven cells in B5:B15 contain numbers greater than zero. Note that cell B9 is excluded since it is equal to zero. Also notice that we supply the criteria in double quotes (">0"). COUNTIF is part of a group of Excel functions that split logical expressions into two parts. As a result, when the criteria argument includes logical operators, it must be entered as text surrounded by double quotes (").

Positive including zero

To include zero in the count, use the "greater than or equal to" operator (>=):

=COUNTIF(data,">=0") // returns 8

The result is 8, one more than the formula above since cell B9 is now included in the count.

SUMPRODUCT function

Another way to solve this problem is with the SUMPRODUCT function and Boolean algebra:

=SUMPRODUCT(--(data>0))

Working from the inside out, this expression checks if values in data (B5:B15) are greater than zero:

data>0

Because data contains eleven cells, the result from this expression is an array that contains 11 TRUE and FALSE values:

{TRUE;TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;TRUE;TRUE}

To convert the TRUE and FALSE values to 1s and 0s, we use a double negative (--):

--{TRUE;TRUE;TRUE;FALSE;FALSE;TRUE;FALSE;TRUE;FALSE;TRUE;TRUE}

The resulting array inside the SUMPRODUCT function looks like this:

=SUMPRODUCT({1;1;1;0;0;1;0;1;0;1;1}) // returns 7

With a single array to process, SUMPRODUCT sums the array and returns 7 as the result. To include zero, adjust the logical test like this:

=SUMPRODUCT(--(data>=0)) // returns 8

The result is now 8 since cell B9 is included in the count.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

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.