Counting within Criteria

Written by Allen Wyatt (last updated September 1, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003


There may be times when you need to count the number of cells in a range which fit a specific criteria. For instance, you may want to know how many cells in a range are over a specific threshold. The natural worksheet function to do this task is COUNTIF. As an example, you may want to know how many cells in the range of A1 through C15 contain a value of 120 or more. The following formula provides the proper count:

=COUNTIF(A1:C15,">119")

The only problem is if you want to add a second criterion to the formula. COUNTIF does not allow you to specify multiple criteria, so you need to resort to formula that is a bit more complex. For instance, if you wanted to know how many cells in the range of A1 through C15 contain a value between 120 and 129, inclusive, you could use the following:

=COUNTIF(A1:C15,">119")-COUNTIF(A1:C15,"<130")

This formula first calculates the number of cells with values at 120 or above and then subtracts the number of cells with values of 129 or below. Astute readers will see an immediate problem with this formula, however—it delivers an erroneous result if there are any cells in the range below 120. They are not counted by the first part of the formula, but they are counted in the result by the second part of the formula. To fix this problem the formula should instead appear as follows:

=COUNT(A1:C15)-COUNTIF(A1:C15,">119")-COUNTIF(A1:C15,"<130")

Another way to solve this problem without using the COUNT function is to simply count the cells that contain a value of less than 130 and then subtract the cells that contain a value of less than 120. This formula gives the same result as the last one:

=COUNTIF(A1:C15,"<130")-COUNTIF(A1:C15,"<120")

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2166) applies to Microsoft Excel 97, 2000, 2002, and 2003.

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

Combining Documents

Need to combine quite a few text documents? A macro may be the easiest way to stuff them all into a single Word document.

Discover More

Friendly and Informative Error Handling

When creating macros, it is helpful to know what is going on within the macro itself in case an error crops up. Here's ...

Discover More

Leading Zeros in Page Numbers

Page numbers in Excel printouts are typically simple counters, without much chance for embellishment. If you want to add ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (menu)

Counting Cells with Specific Characters

Excel is used by many people to hold all sorts of data, not just numbers. If you have cells that include meaningful ...

Discover More

Median of Selected Numbers

Need to find a median value in a series of values? It's easy with the MEDIAN function. What isn't as easy is to derive ...

Discover More

Counting the Number of Blank Cells

If you need to count the number of blank cells in a range, the function to use is COUNTBLANK. This tip discusses the ...

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

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

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.

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.