Exit to Learning Dashboard

COUNTIF Function

Step-by-Step Guide to Understanding the "COUNTIF" Function in Excel

Dec. 6, 2023
4m Read

How to Use COUNTIF Function in Excel?

The Excel “COUNTIF” function is used to count the number of cells in a selected range that meets a specific condition.

Given one criterion, the COUNTIF function searches for an exact match to determine the total number of cells under which the condition is met.

For instance, the criteria could be related to finding the number of cells with values greater than, less than, or equal to a specific value.

The primary drawback to the “COUNTIF” function is that only one condition is supported. If the criteria in question consists of multiple conditions, the “COUNTIFS” function would be the more practical alternative.

In addition, the criterion is not case-sensitive, so the use of upper or lower case spelling in the text string does not affect the outcome.

Excel COUNTIF Function Formula

The formula for using the COUNTIF function in Excel is as follows.

=COUNTIF(range, criterion)
  • Range → The selected range containing the data set across which the function will search for the cells that match the stated criteria.
  • Criterion → The specific condition that must be met in order for the function to count the cell.

Numeric Criterion Syntax: Logical Operator

The range can contain text strings and numbers, whereas the criterion most often contains a logical operator such as:

Logical OperatorDescription
>Greater Than
<Less Than
=Equal To
>=Greater Than or Equal To
<=Less Than or Equal To
<>Not Equal To

Text Strings, Date, Blank and Non-Blank Criterion

For text or date-based conditions, it is necessary to enclose the criterion in double quotes, otherwise the formula will not work.

CriterionDescription
Text
  • The criterion can also be related to containing certain text, such as the name of a city (e.g. “Boston”).
  • There are exceptions to the necessity of the double quotes, however, such as for “True” or “False”.
Date
  • The date criteria can count the entries that match a specific date (and must be wrapped in parentheses)
Blank Cells
  • The (””) double quote (with nothing in between the quotes) can count the number of blank cells in the chosen range.
Non-Blank Cells
  • The ”<>” operator can be used to count the number of non-blank cells
Cell References
  • Cell references in the criteria should not be enclosed in quotes. For instance, the proper format if counting cells greater than cell B1 would be ">"&B1

Wildcards in Criterion

The term “wildcards” refer to special characters such as a question mark, asterisk, or tilde.

WildcardDescription
(?)
  • A question mark in the criteria will match any one character.
(*)
  • An asterisk in the criteria will match zero (or more) characters of any sort, so any cells that contain a specific word.
  • For example, “*th” will count any cell that ends in “th”, and "x*” will count cells that begin with “x”.
(~)
  • A tilde matches a wildcard, e.g. “~?” would count any cells ending with a question mark.

COUNTIF Function Calculator – Excel Model Template

We’ll now move on to a modeling exercise, which you can access by filling out the form below.

Excel Template IconDownload Icon

Part 1. Numeric Criteria COUNTIF Function Examples

Suppose we’re given the following range of numeric data to count the number of cells that meet various types of conditions.

The range is on the left column, while the condition is on the right column.

RangeCondition
10Equal to 10
12Greater Than 10
15Less Than 10
14Greater Than or Equal to 10
6Less Than or Equal to 10
8Not Equal to 10
12Blank Cells
10Non-Blank Cells

The COUNTIF equations that we’ll use to count the matching cells are the following:

=COUNTIF($B$6:$B$13,10) → Count = 2
=COUNTIF($B$6:$B$13,">10") → Count = 4
=COUNTIF($B$6:$B$13,"<10") → Count = 2
=COUNTIF($B$6:$B$13,">=10") → Count = 6
=COUNTIF($B$6:$B$13,"<=10") → Count = 4
=COUNTIF($B$6:$B$13,"<>10") → Count = 6
=COUNTIF($B$6:$B$13,"") → Count = 0
=COUNTIF($B$6:$B$13,"<>") → Count = 8
COUNTIF Function Excel Numeric Criteria

Part 2. Text Strings COUNTIF Function Examples

In the next section, we’ll work with the following data set of text strings, which are cities in this case.

RangeCondition
New York CityEqual to Austin
AustinEnds in “n”
BostonStarts with “s”
San FranciscoContains Five Characters
Los AngelesContains Space in Between
MiamiContains Text
SeattleContains “City”
ChicagoNot Miami

The COUNTIF function equations that we’ll enter into Excel to count the cells that meet each of the corresponding criteria are the following:

=COUNTIF($B$17:$B$24,"=Austin") → Count = 1
=COUNTIF($B$17:$B$24,"*n") → Count = 2
=COUNTIF($B$17:$B$24,"s*") → Count = 2
=COUNTIF($B$17:$B$24,"??????") → Count = 2
=COUNTIF($B$17:$B$24,"* *") → Count = 3
=COUNTIF($B$17:$B$24,"*") → Count = 8
=COUNTIF($B$17:$B$24,"City") → Count = 1
=COUNTIF($B$17:$B$24,"<>Miami") → Count = 7
Excel COUNTIF Function Text Strings
Comments

No comments yet.