How to Use the COUNTIF Function in Excel: Examples, Blanks, Wildcards

The Excel COUNTIF function counts the cells in a range that meet one condition: how many orders are from one region, how many scores are above 80, how many cells are empty. The formula is short, but blanks, wildcards and “or” logic trip people up. This guide uses one ten-row list, and every result below was worked out by hand from that list, including the shortcuts that return a believable but wrong count.

Excel COUNTIF function example: counting rows by department with a ten-row list
COUNTIF counts the cells that meet one condition, shown on a ten-row sample list

COUNTIF syntax

=COUNTIF(range, criteria)

range is the group of cells to look at. criteria is the test, and both arguments are required. COUNTIF takes exactly one condition. Text is not case-sensitive, so “sales” and “Sales” count the same cells.

Excel COUNTIF syntax in three steps: range, criteria in quotes, Enter
The COUNTIF formula takes a range and one criteria
광고

A worked example

Type this list into A1:D11 of a new sheet, with the dates as real dates. Two scores are left empty on purpose.

A: NameB: DeptC: ScoreD: Joined
2AnnaSales822026-01-12
3BenSales912026-02-03
4CaraSupport672026-02-20
5DanSupport2026-03-08
6EliSales912026-03-15
7FayOps742026-04-02
8GusOps582026-04-19
9HanaSupport912026-05-07
10IanSales452026-05-21
11JoOps2026-06-10

To count the people in Sales, test the Dept column: =COUNTIF(B2:B11,"Sales") returns 4 (Anna, Ben, Eli, Ian). The other departments give 3 for Support and 3 for Ops, and 4 + 3 + 3 = 10, the number of rows. When a set of COUNTIF results does not add back to the row count, a row is being missed by one of the criteria. A number works without quotes: =COUNTIF(C2:C11,91) returns 3.

How to write the criteria

Words and comparison signs go inside double quotes. A plain number does not need them, and you do not type an equals sign for “is equal to”. On the sample list:

You wantFormulaResult
Scores above 80=COUNTIF(C2:C11,">80")4 (82, 91, 91, 91)
Scores of 74 or more=COUNTIF(C2:C11,">=74")5 (adds the 74 itself)
Everyone outside Sales=COUNTIF(B2:B11,"<>Sales")6 (10 − 4)
Depts that start with S=COUNTIF(B2:B11,"S*")7 (Sales 4 + Support 3)
Depts that end with s=COUNTIF(B2:B11,"*s")7 (Sales 4 + Ops 3)
Op plus exactly one character=COUNTIF(B2:B11,"Op?")3 (Ops)
Scores above 80, as a share=COUNTIF(C2:C11,">80")/COUNT(C2:C11)0.5, which is 50% when formatted as a percentage (4 of the 8 scores)
Common Excel COUNTIF criteria with results for greater than, not equal, wildcard and blank
Six COUNTIF criteria and what each returns on the sample list

* matches any run of characters (including none) and ? matches exactly one. To find a real asterisk or question mark, put a tilde in front of it, as in "~*". Wildcards only match text, so a numeric cell never matches one.

광고

Put the criteria in a cell: the ampersand rule

Say F1 holds 80. A bare reference works for “equal to”: =COUNTIF(C2:C11,F1) counts scores equal to 80, which is 0 here. When you also need an operator, join the two with an ampersand: =COUNTIF(C2:C11,">"&F1) returns 4, the same as typing “>80”. The same works with functions: =COUNTIF(C2:C11,">"&AVERAGE(C2:C11)) counts scores above the average. The eight scores add up to 599, the average is 74.875, and 82, 91, 91 and 91 beat it, so the result is 4.

The slips are ">F1", which compares against the text F1 instead of the cell, and >80 with no quotes at all, which Excel refuses as a formula. Typing a department without quotes, as in COUNTIF(B2:B11,Sales), gives a #NAME? error because Excel reads Sales as a name.

Counting blanks and non-blanks

Empty cells need their own criteria. On the Score column, which has two empty cells:

FormulaResultWhat it counts
=COUNTIF(C2:C11,"")2Blank cells (and cells holding an empty string)
=COUNTIF(C2:C11,"<>")8Cells that are not blank
=COUNTBLANK(C2:C11)2Blank cells, same as the first row
=COUNT(C2:C11)8Numbers only

Careful with empty criteria cells: if the criteria points at an empty cell, COUNTIF reads it as 0 and counts cells containing 0, not empty cells (Exceljet documents this). To match blanks on purpose, use =COUNTIF(C2:C11,F1&""). Also, a cell holding a formula that returns “” is counted by "" but not by the criteria "=", according to Ablebits.

Dates as criteria

Dates are numbers, so the same operators apply. Build the date with DATE or point to a cell, because a date typed as text can be read differently depending on regional settings. People who joined on or after April 1: =COUNTIF(D2:D11,">="&DATE(2026,4,1)) returns 5 (Apr 2, Apr 19, May 7, May 21, Jun 10). Before April it is 5 as well, and 5 + 5 = 10. COUNTIF takes one date condition, so a window such as February needs COUNTIFS: =COUNTIFS(D2:D11,">="&DATE(2026,2,1),D2:D11,"<"&DATE(2026,3,1)) returns 2 (Feb 3, Feb 20).

Two conditions: AND, OR and the double-count trap

AND means COUNTIFS, which takes up to 127 range and criteria pairs, and all ranges must be the same size or the result is #VALUE!. People in Sales with a score of 80 or more: =COUNTIFS(B2:B11,"Sales",C2:C11,">=80") returns 3 (Anna, Ben, Eli). A range between two limits uses the same column twice: =COUNTIFS(C2:C11,">=60",C2:C11,"<=90") returns 3 (82, 67, 74).

OR on one column: put the choices in curly braces and wrap the whole thing in SUM. =SUM(COUNTIF(B2:B11,{"Sales","Ops"})) returns 7 (4 + 3). The braces make COUNTIF return two counts and SUM adds them.

OR across two columns is where the wrong answer hides. “In Sales, or scored 90 or more”: adding two COUNTIFs gives =COUNTIF(B2:B11,"Sales")+COUNTIF(C2:C11,">=90") = 4 + 3 = 7. But Ben and Eli are in both groups, so they are counted twice. The real answer is 5 (Anna, Ben, Eli, Ian, Hana). Subtract the overlap: =COUNTIF(B2:B11,"Sales")+COUNTIF(C2:C11,">=90")-COUNTIFS(B2:B11,"Sales",C2:C11,">=90") = 4 + 3 − 2 = 5.

Excel COUNTIFS for AND and SUM COUNTIF for OR with results on the sample list
AND, OR and unique counts worked out by hand

Find duplicates and count unique values

To flag repeats, put =COUNTIF($C$2:$C$11,C2)>1 next to each row and copy it down: 91 appears three times, so Ben, Eli and Hana show TRUE. To count the different departments, =SUMPRODUCT(1/COUNTIF(B2:B11,B2:B11)) returns 3: each Sales row adds 1/4, each Support row 1/3 and each Ops row 1/3, which sum to 1 + 1 + 1. This formula returns #DIV/0! if the range has blank cells, and it gets slow on large data. In Excel 365, =COUNTA(UNIQUE(B2:B11)) is simpler.

Why COUNTIF returns the wrong count

A stray space. If a cell holds “Sales ” with a trailing space, "Sales" will not match it, so the count comes up short without any error. Clean the column with TRIM, or use "Sales*".

Long numbers. Exceljet states that COUNTIF does not correctly count numbers longer than 15 digits, which matters for IDs and card numbers stored as numbers. A common workaround is to compare as text: =COUNTIF(A2:A100,A2&"*"), or =SUMPRODUCT(--(A2:A100=A2)). Test either one on a few known values before trusting it.

Long text. Microsoft says COUNTIF returns wrong results when it matches strings longer than 255 characters. Shorten the criteria, or split it with the ampersand as Microsoft’s page suggests.

Case matters to you but not to Excel. "east" and "East" count alike. For a case-sensitive count use =SUMPRODUCT(--EXACT(B2:B11,"Sales")), which returns 4 for “Sales” and 0 for “sales”.

Excel COUNTIF checklist: quotes, ampersand, spaces, blanks, AND and OR, long numbers
Six checks before you trust a COUNTIF result

Google Sheets uses the same =COUNTIF(range, criterion), with the same *, ? and tilde wildcards, one criterion only and no case sensitivity. For several conditions use COUNTIFS there too.

Frequently asked questions

What does the COUNTIF function do in Excel?

It counts the cells in a range that meet one condition. =COUNTIF(B2:B11,"Sales") counts how many cells in column B contain Sales.

How do I use COUNTIF with greater than?

Put the operator and the number in quotes: =COUNTIF(C2:C11,">80"). If the limit is in a cell, join it with an ampersand: =COUNTIF(C2:C11,">"&F1).

How do I count blank or non-blank cells with COUNTIF?

Use =COUNTIF(range,"") for blanks and =COUNTIF(range,"<>") for cells that are not blank. COUNTBLANK gives the same count as the first.

Can COUNTIF use more than one condition?

No, it takes one. Use COUNTIFS for “and”, which accepts up to 127 range and criteria pairs. For “or” on one column, wrap COUNTIF with an array of choices inside SUM.

Why does COUNTIF return 0 or the wrong number?

Check for stray spaces in the data, operators outside quotes, cell references that are not joined with an ampersand, numbers longer than 15 digits, and criteria text longer than 255 characters.

Sources: Last checked November 2026. Microsoft Support: COUNTIF function; Exceljet: COUNTIF; Ablebits: COUNTIF examples; Google: COUNTIF in Google Sheets.

광고

#ExcelCOUNTIF  #COUNTIFFunction  #ExcelFormulas  #COUNTIFS  #CountBlankCells  #Wildcards  #ExcelTips  #ExcelCriteria  #GoogleSheets  #MetaTrend

Found this useful? Share it.