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)| Argument | What it means | |
|---|---|---|
range | Required | The cells to test. Must be a real range on a sheet, not an array calculated by another formula. |
criteria | Required | The 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?
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Invoice | Status | Amount | ||
| 2 | INV-301 | Paid | 1450 | 3 | |
| 3 | INV-302 | Overdue | 820 | ||
| 4 | INV-303 | Paid | 2300 | ||
| 5 | INV-304 | Open | 640 | ||
| 6 | INV-305 | paid | 1100 | ||
| 7 | INV-306 | Overdue | 3150 |
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
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Invoice | Status | Amount | Threshold | 1000 |
| 2 | INV-301 | Paid | 1450 | ||
| 3 | INV-302 | Overdue | 820 | 4 | |
| 4 | INV-303 | Paid | 2300 | ||
| 5 | INV-304 | Open | 640 | ||
| 6 | INV-305 | paid | 1100 | ||
| 7 | INV-306 | Overdue | 3150 |
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
| A | B | C | |
|---|---|---|---|
| 1 | Customer email | ||
| 2 | [email protected] | 2 | |
| 3 | [email protected] | ||
| 4 | [email protected] | ||
| 5 | [email protected] | ||
| 6 | [email protected] |
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
| A | B | |
|---|---|---|
| 1 | Order no. | |
| 2 | A-1001 | |
| 3 | A-1002 | TRUE |
| 4 | A-1003 | |
| 5 | A-1002 | |
| 6 | A-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.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
Result is 0 when matches exist | Extra 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 accepted | The 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.
| Language | Function name |
|---|---|
| Danish | TÆL.HVIS |
| Dutch | AANTAL.ALS |
| Finnish | LASKE.JOS |
| French | NB.SI |
| German | ZÄHLENWENN |
| Hungarian | DARABTELI |
| Italian | CONTA.SE |
| Norwegian (Bokmål) | ANTALL.HVIS |
| Polish | LICZ.JEŻELI |
| Portuguese (Brazil) | CONT.SE |
| Portuguese (Portugal) | CONTAR.SE |
| Russian | СЧЁТЕСЛИ |
| Spanish | CONTAR.SI |
| Swedish | ANTAL.OM |
| Turkish | EĞERSAY |
Recipes that use COUNTIF
- How to check if a cell contains a word in Excel
- How to count cells by color in Excel
- How to count cells that contain text in Excel
- How to count unique values in Excel
- How to create a drop-down list in Excel
- How to find duplicates between two lists in Excel
- How to get the nth match in Excel
- How to highlight duplicates in Excel