Statistical function

COUNTIF function

Counts the cells in a range that meet one condition, such as invoices marked "Paid", scores above 50 or emails containing "@gmail".

Available in All versions of Excel, Excel for the web, Excel for Mac

In every Excel versionWorks in Google Sheets

Syntax

COUNTIF(range, criteria)
ArgumentWhat it means
rangeRequiredThe cells to test. Must be a real range on a sheet, not an array calculated by another formula.
criteriaRequiredThe condition. A value ("Paid", 100), a comparison in quotes (">=1000"), a wildcard pattern ("*gmail*"), or an operator joined to a cell (">="&F1).

Returns: A whole number: how many cells meet the condition.

How COUNTIF works

COUNTIF counts with a filter: it looks at every cell in a range and counts the ones that pass your test. It is one of the most used functions in business spreadsheets, answering questions like "how many invoices are overdue?", "how many staff are in Sales?" or "how many orders were over €1,000?"

The criterion is written the same way in COUNTIF, SUMIF, AVERAGEIF and their -IFS cousins. Text comparisons ignore upper and lower case. Operators (>, <, >=, <=, <>) must go inside quotes, and to compare with another cell you join the operator to it with &. Wildcards let you match patterns: * means "any number of characters" and ? means "exactly one character".

COUNTIF handles one condition. For two or more (Paid and over 1,000) use COUNTIFS. Because the first argument has to be a sheet range, you cannot feed it the result of another formula; in Microsoft 365 the FILTER or SUM(--(...)) patterns cover those cases.

Examples

1How many invoices are paid?

E2fx=COUNTIF(B2:B7, "Paid")
ABCDE
1InvoiceStatusAmount
2INV-301Paid14503
3INV-302Overdue820
4INV-303Paid2300
5INV-304Open640
6INV-305paid1100
7INV-306Overdue3150

Result: 3

INV-301, INV-303 and INV-305 have the status Paid. The match is not case-sensitive, so the lower-case "paid" on INV-305 is included and the answer is 3.

2Invoices at or above a threshold in a cell

E3fx=COUNTIF(C2:C7, ">="&E1)
ABCDE
1InvoiceStatusAmountThreshold1000
2INV-301Paid1450
3INV-302Overdue8204
4INV-303Paid2300
5INV-304Open640
6INV-305paid1100
7INV-306Overdue3150

Result: 4

E1 holds the threshold 1000. The formula builds the text ">=1000" and counts the amounts that pass: 1,450, 2,300, 1,100 and 3,150, so 4 invoices. Change E1 and the count updates.

3Wildcard: customers using Gmail

Result: 2

The asterisk stands for any characters before "@gmail.com", so the pattern matches [email protected] and [email protected]. To find the text anywhere in the cell, put an asterisk on both sides, e.g. "*northwind*".

4Flag duplicate order numbers

B3fx=COUNTIF($A$2:$A$6, A3)>1
AB
1Order no.
2A-1001
3A-1002TRUE
4A-1003
5A-1002
6A-1004

Result: TRUE

In B3 the formula counts how often A-1002 appears in the whole list (twice) and checks whether that is more than 1. Filled down column B it shows TRUE next to both A-1002 rows and FALSE elsewhere. The dollar signs keep the list fixed while the row changes.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 18 KB

Common errors and how to fix them

ErrorWhy it happensFix
Result is 0 when matches existExtra spaces in the data, numbers stored as text, or a comparison written without quotes.Clean the data with TRIM; write comparisons as text such as ">=1000".
#VALUE!A text criterion longer than 255 characters, or a link to a closed workbook.Shorten the criterion (compare with LEFT in a SUMPRODUCT) or open the source workbook.
Formula not acceptedThe first argument is an array, e.g. COUNTIF(UPPER(A2:A6), ...).Use =SUM(--(UPPER(A2:A6)="X")) instead.

Tips

  • Count non-empty cells with "<>" and empty ones with "".
  • To count a literal asterisk or question mark put a tilde in front: "~*".
  • Count several values at once with an array constant: =SUM(COUNTIF(B2:B7, {"Paid","Open"})).

Questions

Can COUNTIF count cells with text in them?

Yes: =COUNTIF(A2:A10, "*") counts every cell that contains text (numbers are not counted by this wildcard).

Is COUNTIF case-sensitive?

No. For a case-sensitive count use =SUMPRODUCT(--EXACT(B2:B7, "Paid")).

How do I count between two numbers?

Use COUNTIFS with the same range twice: =COUNTIFS(C2:C7, ">=500", C2:C7, "<=1500").

Google Sheets

COUNTIF also exists in Google Sheets and works the same way for everyday use, so the examples above work there too.

COUNTIF in other languages

In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.

LanguageFunction name
DanishTÆL.HVIS
DutchAANTAL.ALS
FinnishLASKE.JOS
FrenchNB.SI
GermanZÄHLENWENN
HungarianDARABTELI
ItalianCONTA.SE
Norwegian (Bokmål)ANTALL.HVIS
PolishLICZ.JEŻELI
Portuguese (Brazil)CONT.SE
Portuguese (Portugal)CONTAR.SE
RussianСЧЁТЕСЛИ
SpanishCONTAR.SI
SwedishANTAL.OM
TurkishEĞERSAY

Recipes that use COUNTIF