Counting Names Based on Two Criteria

Written by Allen Wyatt (last updated May 18, 2019)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


Rod has a Christmas card list in Excel. (Actually, this question could apply to any greeting card list.) Each name has a unique numeric ID associated with it and is color coded based on whether the name is family, friend, school friend, or work friend. He also has a True/False indicator in a column which indicates whether the person is to receive a card this year. Rod would like to count how many cards fit two criteria: the "gets card" indicator is True, and the ID is 50 or below. Alternatively, he'd like a way to count the number of cards where the "gets card" indicator is True, and the color code is red.

If you only have to get such sub-lists periodically, the easiest and most flexible solution might be to use the filtering capabilities of Excel and then use the SUBTOTAL function to determine the count. You can filter to display rows based upon almost any criteria you want. When the list represents what you want, then you can use a formula such as the following:

=SUBTOTAL(3,B2:B100)

This variation on the SUBTOTAL function returns a count of all displayed rows in the specified range. The key here is that the only rows displayed are those that meet your filtering criteria, so the formula returns the count you want.

There are also formulas that will return the desired information. The COUNTIFS function will look at multiple criteria and return a count based upon the result of the comparisons. For instance, the following formula will provide the number of list members where the "gets card" indicator is True, and the ID is 50 or below:

=COUNTIFS(A2:A100,"<50",B2:B100,TRUE)

The formula only looks at list members in A2:A100, and it assumes that B2:B100 contains the True/False values serving as the "gets card" indicator.

You should remember that the COUNTIFS function was introduced beginning with Excel 2007. If you are creating a workbook that will also be used by those with an older version of Excel, then you may want to use an alternative function to return the count:

=SUMPRODUCT((A2:A100<50)*B2:B100*1)

If you want to take cell color into account in your formulas, then it becomes a bit trickier. You can devise a user-defined function (a macro) that returns cell color and then use that in the formula. (Other issues of ExcelTips have discussed such functions.) An easier way which avoids the macro is to add a column to your data that contains a numeric value indicating which group (family, friend, school friend, or work friend) the individual belongs to. Then you can include the column value in your formulas.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12867) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

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

Displaying the Outlining Toolbar by Default

The Outlining toolbar contains tools that are helpful to use, even if you aren't working on your document's outline. This ...

Discover More

Double-Spacing Your Document

Need to produce a quick double-spaced printout of your document? You can do it by using the simple steps in this tip.

Discover More

Setting the Starting Line Number

Line numbers are an important part of some documents, such as those prepared in the legal profession. If you want to ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Counting Occurrences of Words

If you would like to determine how many instances of a particular word appear within a range of text, there are several ...

Discover More

Strange Value Results in a Cell

When Excel performs a calculation, the results you see in an unformatted cell may cause a bit of concern. This tip ...

Discover More

Working with Imperial Linear Distances

Excel works with decimal values very easily. It is more difficult for the program to work with non-decimal values, such ...

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 six minus 2?

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