Count what matches with COUNTIF

Counting · About 5 minutes

Count what matches with COUNTIF

COUNTIF counts the cells in a range that match a rule. The rule is called a condition.

How COUNTIF countsThe formula =COUNTIF(B2:B7,"Sales") over a staff list. COUNTIF looks at each department in B2 to B7. The four cells that say Sales are counted 1, 2, 3, 4; Accounts and HR are skipped. The count, 4, lands in B9.=COUNTIF(B2:B7,"Sales")AB123456789NameDepartmentPriya NairSalesArjun MehtaAccountsFatima ShaikhSalesVikram RaoSalesNeha GuptaSalesSuresh IyerHRIn Sales41234

How COUNTIF counts

Exercise 1 of 3 · Worked example

In B9, count the staff in Sales. Type =COUNTIF(B2:B7,"Sales") and press Enter.

ABC
1NameDepartmentSalary ($)
2Priya NairSales52,000
3Arjun MehtaAccounts64,000
4Fatima ShaikhSales47,500
5Vikram RaoSales66,000
6Neha GuptaSales69,000
7Suresh IyerHR78,000
8
9In Sales (answer cell)

Questions people ask

How do I COUNTIF greater than a number?

Put the sign and number in quotes: =COUNTIF(C2:C20,">40000"). To use a number from a cell, join it with &: =COUNTIF(C2:C20,">"&E1).

How do I count cells that are not blank with COUNTIF?

Use "<>" as the condition: =COUNTIF(B2:B20,"<>").

Is COUNTIF case-sensitive?

No. "sales", "Sales" and "SALES" all match the same cells.

How do I use COUNTIF with more than one condition?

Use COUNTIFS. It takes a range and a condition for each test.

Why is my COUNTIF returning 0?

Often the sign is outside the quotes, the cells have stray spaces, or the numbers are stored as text. Check one matching cell by eye first.

How do I find duplicates with COUNTIF?

Fill down =COUNTIF($A$2:$A$50,A2)>1 beside the list. It shows TRUE for every value that appears more than once. How to find duplicates in Excel with COUNTIF

Theme

How COUNTIF counts

The formula =COUNTIF(B2:B7,"Sales") over a staff list. COUNTIF looks at each department in B2 to B7. The four cells that say Sales are counted 1, 2, 3, 4; Accounts and HR are skipped. The count, 4, lands in B9.