Excel: Count Records That Match a Criterion

This page is an advertiser-supported excerpt of the book, Power Excel 2010-2013 from MrExcel - 567 Excel Mysteries Solved. If you like this topic, please consider buying the entire e-book.


Problem: I have a large data set. I want to count the number of records that meet a certain criterion.

  1. Count males and females.

    Strategy: You use the COUNTIF function, which requires two arguments: a range of cells that you want to test and a criteria. To count the records where the gender is M, you use =COUNTIF(B5:B60,"œM").

  2. COUNTIF function looks through a range, counting matches.

    Note that the second argument, "œM", tells Excel to count records that are equal to M. Because this function is not case-sensitive, the function will count cells with values of M or m.

    If you want to count the records where the age is a specific number, you can write the formula either with or without quotes around the number:

    =COUNTIF(D5:D60,32)

    =COUNTIF(D5:D60,"œ32")

    You can also establish a criterion to look for items that are below or above a certain number:

    =COUNTIF(D5:D60,"œ<21")

    A criterion can include a wildcard character. To find any text that contains XYZ, you use the following formula:

    =COUNTIF(A2:A999,"*XYZ*")