SQLExcelHTML & CSSTouch typingBlogChoose a course
Lurndo › Blog › Excel
  1. Short answer
  2. What does COUNTIF do in Excel?
  3. How do you write a COUNTIF formula?
  4. Example: how many items of clothing did the shop sell?
  5. How do you count numbers greater than or less than a value?
  6. How do you count with wildcards?
  7. How do you count blank and non-blank cells?
  8. How do you find duplicates with COUNTIF?
  9. Why is COUNTIF counting wrong?
  10. Which functions are like COUNTIF?
  11. Frequently asked questions

COUNTIF examples: how to count text, numbers, blanks and duplicates in Excel

One function, two arguments, and it still miscounts more often than you'd think. On a charity shop's sheet you'll see every kind of criterion at work, and you'll type the formula yourself.

C

Christophe, founder of Lurndo
November 5, 2026 · 12 min read

COUNTIF counts how many cells in a range meet one condition, as in =COUNTIF(B2:B16,"Clothing") for every cell that says Clothing. The criterion can be text, a number, a comparison such as ">10" or a cell that you join to the operator with &. Wildcards match part of a text, and "" counts blank cells. Upper and lower case don't matter, but spaces do. When two conditions must both be true, use COUNTIFS.

Exercise: right in your browser, on real data

Practise this: the lesson on COUNTIF, free

Sources: 8 sources you can check

A row of blank paper cells laid out like stepping stones, with small green paper flags planted on some of them, and a round paper tally counter with a blank window beside the row, on pale green paper.

What does COUNTIF do in Excel?

COUNTIF counts how many cells in a range meet one condition. =COUNTIF(B2:B16,"Clothing") runs through cells B2 to B16 and finds six that say Clothing. It counts cells, it doesn't add up amounts. If you want to know what that clothing brought in, you need SUMIF. In a Dutch version of Excel, by the way, COUNTIF is called AANTAL.ALS.

Criterion: the condition a cell has to meet to be counted, such as "Clothing" or ">10". Microsoft calls the argument criteria.

The basics, explained on a sheet that lights up as you go, are in our lesson COUNTIF: counting what matches. This article is the reference to go with it: counting with operators such as > and <>, with a limit in a cell, with wildcards, blank cells and duplicates. And you'll see why COUNTIF sometimes returns 0 when you're sure there's something to count.

How do you write a COUNTIF formula?

COUNTIF takes two arguments: the range Excel counts in, and the criterion a cell has to meet (Microsoft). There's room for exactly one criterion. If you need to check two things at once, such as the category and the price, you'll want COUNTIFS, which comes up later in this article.

=COUNTIF(range,criteria)
ArgumentWhat it isExamples
rangeThe cells Excel runs throughB2:B16, C2:C16
criteriaText, a number, a comparison or a cell"Clothing", 3, ">10", G2

Text and anything with an operator such as > goes in quotation marks. A plain number or a cell reference doesn't need them.

The comma between the arguments isn't fixed. According to Microsoft, the most common list separators are the comma and the semicolon, and which one you get depends on your operating system's locale and your Excel settings, not on Windows or Mac (Microsoft). In an English Excel set up for a country where the comma is the decimal mark, as in much of mainland Europe, the same formula reads =COUNTIF(B2:B16;"Clothing").

Example: how many items of clothing did the shop sell?

The Second Chance charity shop in Gloucester is the fourth client in our Excel course. Its coordinator, Yasmina, puts every sale of the week on its own row: the item, the category, the price, the day and the volunteer at the till. Every example in this article works on this sheet, with all fifteen sales, so you can check each result yourself.

RowA: ItemB: CategoryC: Price (£)D: DayE: Volunteer
2Dress greenClothing12MonSophie
3Book fictionBooks2MonOmar
4LampHousehold8TueSophie
5T-shirt SClothing3TueGrace
6Dressing gownClothing6WedOmar
7PuzzleToys4WedGrace
8Book cookingBooks3ThuSophie
9RadioElectrical15ThuOmar
10T-shirt XLClothing4FriSophie
11Dress blackClothing18FriGrace
12What? GameToys5SatOmar
13VaseHousehold7SatGrace
14T-shirt MClothing3SatSophie
15BookendHousehold9SatOmar
16Kids' bikeToys35SatGrace

Row 1 holds the column headers. G2 holds a price limit of £10, which you'll need further on.

=COUNTIF(B2:B16,"Clothing")

The formula returns 6: Dress green, T-shirt S, Dressing gown, T-shirt XL, Dress black and T-shirt M. Excel runs down column B and adds one for every cell that equals the criterion. Upper and lower case play no part (Microsoft), so "clothing" gets you 6 as well. The quotation marks do matter. Without them, Excel reads the word as the name of something else, and that doesn't exist.

Now try it yourself, on another column. The exercise runs on the real Second Chance sheet, and you type the formula the way your own Excel does: with commas and English names, or with semicolons and the names of your language. First find the column that holds the days.

Try it: the Saturday sales

How many sales did the shop make on Saturday? Count them in I2 with COUNTIF.

ABCDEFGHIJ
1ItemCategoryPriceDayVolunteerLimit
2Dress greenClothing£12.00MonSophie£10.00
3Book fictionBooks£2.00MonOmar
4LampHousehold£8.00TueSophie
5T-shirt SClothing£3.00TueGrace
6Dressing gownClothing£6.00WedOmar
7PuzzleToys£4.00WedGrace
8Book cookingBooks£3.00ThuSophie
9RadioElectrical£15.00ThuOmar
10T-shirt XLClothing£4.00FriSophie
11Dress blackClothing£18.00FriGrace
12What? GameToys£5.00SatOmar
13VaseHousehold£7.00SatGrace
14T-shirt MClothing£3.00SatSophie
15BookendHousehold£9.00SatOmar
16Kids' bikeToys£35.00SatGrace
17
I2

How do you count numbers greater than or less than a value?

Put a comparison operator in front of the number, and put the operator and the number together in quotation marks: ">10", not >10. That way you count everything above, below or apart from a limit. Here are the six operators, each used on the prices in column C or the categories in column B of the sheet above:

OperatorMeansFormulaResult
>greater than=COUNTIF(C2:C16,">10")4
<less than=COUNTIF(C2:C16,"<5")6
>=greater than or equal to=COUNTIF(C2:C16,">=12")4
<=less than or equal to=COUNTIF(C2:C16,"<=5")7
<>not equal to=COUNTIF(B2:B16,"<>Clothing")9
=equal to, can be left out=COUNTIF(C2:C16,3)3

<> works on text too: "<>Clothing" counts the nine sales that aren't clothing.

Watch the difference between < and <=. £5 or less gives 7, less than £5 gives 6: the game at exactly £5 drops out with "<5". Limits like these are the classic trap. When a question says "up to", "from" or "more than", read it twice before you pick the operator. You'll practise them in the lesson criteria with operators.

Dates work the same way, because Excel stores dates as sequential serial numbers (Microsoft). If A2:A20 holds dates, =COUNTIF(A2:A20,">="&DATE(2026,1,1)) counts every date from 1 January 2026 on. With DATE there's no doubt about which number is the day and which is the month.

How do you use a cell as the criterion?

Join the operator and the cell with &. Yasmina keeps her price limit of £10 in G2, and =COUNTIF(C2:C16,">"&G2) turns that into the criterion ">10": 4 items. When she changes the limit, the formula recounts straight away. Microsoft builds its own example the same way, with "<>"&B4 (Microsoft).

">G2" gives you 0. Inside the quotation marks, G2 is just text, so Excel looks for prices greater than the word G2. The operator goes inside the quotation marks, the reference outside.

Try it yourself, with the limit in G2. This time we also check your formula on a second, hidden version of the sheet, with other prices and another limit. That way you'll know at once whether your count follows the limit when it changes.

Try it: pricier than the limit

Count in I2 how many items cost more than the limit in G2. If Yasmina changes the limit, your count has to follow.

ABCDEFGHIJ
1ItemCategoryPriceDayVolunteerLimit
2Dress greenClothing£12.00MonSophie£10.00
3Book fictionBooks£2.00MonOmar
4LampHousehold£8.00TueSophie
5T-shirt SClothing£3.00TueGrace
6Dressing gownClothing£6.00WedOmar
7PuzzleToys£4.00WedGrace
8Book cookingBooks£3.00ThuSophie
9RadioElectrical£15.00ThuOmar
10T-shirt XLClothing£4.00FriSophie
11Dress blackClothing£18.00FriGrace
12What? GameToys£5.00SatOmar
13VaseHousehold£7.00SatGrace
14T-shirt MClothing£3.00SatSophie
15BookendHousehold£9.00SatOmar
16Kids' bikeToys£35.00SatGrace
17
I2

Your formula ran in your own browser, on a real calculation engine. We check the result, not the spelling, so a different formula that finds the same count is fine too. Anyone who typed ">10" got the right number here and the wrong one on the hidden sheet, with its other limit. That's exactly what happens in real life when someone changes the limit.

How do you count with wildcards?

A wildcard lets you count text you don't know exactly. The asterisk * stands for any number of characters, including none. The question mark ? stands for exactly one character (Microsoft). No item is called just Dress, but a wildcard finds them anyway:

FormulaResultWhat counts
=COUNTIF(A2:A16,"Dress*")3Dress green, Dressing gown and Dress black
=COUNTIF(A2:A16,"Dress *")2Dress green and Dress black: a space has to follow Dress
=COUNTIF(A2:A16,"*book*")3Book fiction, Book cooking and Bookend
=COUNTIF(A2:A16,"T-shirt ?")2T-shirt S and T-shirt M, not XL: that's two characters
=COUNTIF(A2:A16,"What~?*")1What? Game: with the tilde, ? is a plain question mark

To find an actual asterisk or question mark, put a tilde (~) in front of it. And "*" on its own counts every cell with text, Microsoft says: in column A, =COUNTIF(A2:A16,"*") returns 15, in column C it returns 0, because that's all numbers. You'll find more examples on the same items in the lesson wildcards.

How do you count blank and non-blank cells?

Use "" as the criterion to count blank cells and "<>" to count everything that isn't blank. The Green Fingers allotments in Harrogate, another client in the course, track each plot's tenant and harvest. Plot P04 is vacant, and P09 grew no tomatoes this year:

RowA: PlotB: TenantD: Tomatoes (kg)
2P01Molly18.4
3P02Karim7.9
4P03Annabel21.6
5P04
6P05Will30.2
7P06Sophie6.5
8P07Ben15.7
9P08Fatima27.9
10P09Luke
11P10Jodie19.3

Column C, the area, is left out here. The blank cells are truly empty: no space, no formula.

=COUNTIF(B2:B11,"") returns 1, the vacant plot, and =COUNTIF(B2:B11,"<>") returns 9 rented plots. Nothing follows the "not equal to" operator, so every cell that isn't empty counts. Excel also has functions of its own for counting. Here's how they differ on the names in column B and the kilos in column D:

FunctionCountsB2:B11D2:D11
COUNTcells with a number08
COUNTAcells that aren't empty98
COUNTBLANKempty cells12
COUNTIF with "<>"cells that aren't empty98
COUNTIF with "*"cells with text90

COUNT doesn't see the names, because they're text, and "*" doesn't see the kilos, because they're numbers. So decide what you want to count first, and pick the function after. One detail: COUNTBLANK also counts a cell with a formula that returns "", but not a cell holding 0 (Microsoft). You'll practise COUNT and COUNTA in the lesson counting what's there.

How do you find duplicates with COUNTIF?

Let COUNTIF count, for every row, how often its value appears in the whole column. If that's more than once, the value is a duplicate. On the charity shop's sheet, put this formula in F2 and fill it down to F16:

=COUNTIF($B$2:$B$16,B2)>1

Every row returns TRUE except row 9: the radio is the only item in the Electrical category. The dollar signs lock the range while B2 moves on to B3, B4 and so on. Leave them out and the range slides down with the formula, until the one in F16 only looks at B16 and the empty cells below it. On the items in column A, the same formula returns FALSE fifteen times: no item appears twice.

To flag only the second and later appearances, let the range grow. With =COUNTIF($B$2:B2,B2)>1, each row looks only at itself and the rows above it. Rows 2, 3, 4, 7 and 9 now return FALSE, because that's where a category appears for the first time. So there are five categories, and every TRUE is a repeat. Rather see a word than TRUE? Wrap the test in the IF function.

Why is COUNTIF counting wrong?

Usually because a cell looks different from what it is: a number that's really text, a space you can't see. Or because the formula asks something other than what you meant, such as AND where you wanted OR. These are the causes we come across most, each with its fix.

A number is stored as text

If someone enters the radio's £15 as text in C9, =COUNTIF(C2:C16,">10") returns 3 instead of 4. With an operator, COUNTIF only counts real numbers. Excel usually flags such a cell with a small green triangle. Select the cells, click the warning and choose Convert to Number (Microsoft).

A space or an invisible character

"Clothing " with a trailing space is a different value to Excel than "Clothing". If that space sits in B2, "Clothing" only counts 5. Microsoft recommends clearing out leading and trailing spaces, nonprinting characters and a mix of straight and curly quotation marks, with TRIM or CLEAN (Microsoft).

Text longer than 255 characters

When COUNTIF has to match text longer than 255 characters, it returns a wrong result, Microsoft warns on the same page. The fix: cut the criterion into pieces and join them with &, as in =COUNTIF(A2:A5,"long string"&"another long string"). With short values, such as categories or names, you'll never run into this.

A formula from a European colleague

A formula such as =COUNTIF(B2:B16;"Clothing") won't work in an Excel with UK or US settings. Swap the semicolons for commas and it will. In a Dutch version you'd also see a different name, =AANTAL.ALS(B2:B16;"Clothing"). And watch decimals in a criterion, because the decimal mark changes too: ">2,5" becomes ">2.5".

Mixing up OR and AND

If you want clothing or books, add two COUNTIFs together: =COUNTIF(B2:B16,"Clothing")+COUNTIF(B2:B16,"Books") returns 8. Microsoft does the same in its example with apples and oranges. If two conditions must both be true, use COUNTIFS. A row only counts when all its criteria are met (Microsoft).

=COUNTIFS(B2:B16,"Clothing",C2:C16,">5")
=COUNTIFS(B2:B16,"Clothing",B2:B16,"Books")

The first formula finds three items of clothing over £5. The second returns 0, because one cell can't be Clothing and Books at the same time: for "clothing or books" you need the sum of two COUNTIFs. You'll practise COUNTIFS in the lesson several conditions.

Which functions are like COUNTIF?

COUNTIF has a whole family. SUMIF (Microsoft) and AVERAGEIF (Microsoft) take their criterion in the same form, with the same operators and wildcards. Know one and you're halfway to the other. The difference is what they do with the rows that match: count them, add them up or average them. On the charity shop's sheet:

FunctionWhat it doesOn the sheet
COUNTIFScounts with several conditions at onceclothing over £5: 3
SUMIFadds up the amounts that meet a conditionSaturday sales: £59
AVERAGEIFaverages what meets a conditionaverage price of clothing: about £7.67
COUNTcounts cells with a numberprices in C2:C16: 15
COUNTAcounts cells that aren't emptyitems in A2:A16: 15

You'll find more examples, with the same kind of criteria and the same shop, in SUMIF with text, dates and wildcards and how to calculate an average in Excel. And to see the twelve formulas you'll need most, COUNTIF among them, read 12 basic Excel formulas everyone should know.

Counting is easiest to learn on a sheet you can see. In module 4 of our Excel course you do just that at Second Chance, from your first COUNTIF to wildcards and several conditions. Excel practice exercises with explanations shows how those exercises work.

Frequently asked questions

Is COUNTIF case-sensitive?

No. To COUNTIF, clothing, Clothing and CLOTHING are the same, so =COUNTIF(B2:B16,"clothing") also counts every cell that says Clothing. That's usually handy, because not everyone types as neatly. Spaces do count, though: "Clothing " with a trailing space is a different value to Excel, and the formula leaves it out.

How do I use COUNTIF with multiple criteria?

It depends on what you mean. If either one will do, add two COUNTIFs together: =COUNTIF(B2:B16,"Clothing")+COUNTIF(B2:B16,"Books"). If both conditions must be true, such as clothing over £5, use COUNTIFS instead: =COUNTIFS(B2:B16,"Clothing",C2:C16,">5"). It takes a range and a criterion for each condition.

Why is my COUNTIF returning 0?

Usually the criterion doesn't match what's really in the cells. Look for trailing spaces, numbers stored as text, and a cell reference inside the quotation marks, such as ">G2", which looks for the text G2. And check that the range points at the right column.

Can COUNTIF count cells by colour?

No. According to Microsoft, COUNTIF can't count cells based on their background or font colour. You'd need a user-defined function in VBA for that. There's often a simpler way, though. A cell usually gets its colour for a reason, so put that reason in an extra column, such as Paid or Open, and count that column with COUNTIF.

Can COUNTIF count cells on another sheet?

Yes. Put the sheet name and an exclamation mark before the range, as in =COUNTIF(Sales!B2:B16,"Clothing"), or simply click the range while you type the formula. If you point at another workbook, it has to be open: when it's closed, the formula returns #VALUE!, Microsoft says.

Practise this in the course

Every lesson explains first and then lets you practise yourself, with a real spreadsheet in your browser.

  • COUNTIFCounting and adding with conditions · Counting what matches
  • CriteriaCounting and adding with conditions · Criteria with operators
  • WildcardsCounting and adding with conditions · Wildcards
  • SUMIFSCounting and adding with conditions · Several conditions
Start Excel for free

Sources

  1. Microsoft Support, COUNTIF function
  2. Microsoft Support, COUNTIFS function
  3. Microsoft Support, COUNTBLANK function
  4. Microsoft Support, SUMIF function
  5. Microsoft Support, AVERAGEIF function
  6. Microsoft Support, DATE function
  7. Microsoft Support, Convert numbers stored as text to numbers in Excel
  8. Microsoft Support, How to avoid broken formulas in Excel
C

Christophe, founder of Lurndo

Christophe builds Lurndo from Belgium, with short, playful exercises for SQL, Excel, HTML & CSS and touch typing that show straight away what your answer does. On this blog, Christophe answers the questions people run into while learning, with sources you can check yourself.

Read next

  • How to calculate an average in Excel: blanks, zeros, conditions and weighted averagesIt's one function, yet averages go wrong all the time. See how AVERAGE works, what it skips, and how to average without zeros, with a condition or with weights, on real spreadsheets.Excel · November 5, 2026 · 11 min read
  • Excel IF function examples: text, AND, OR, nested IF and IFSOne test, two outcomes and a handful of traps. On a swimming pool's members sheet you'll see IF at work, from a simple choice to three categories, and you'll try it yourself right away.Excel · November 5, 2026 · 12 min read

SQL

  • Topics
  • All lessons
  • Cheat sheet
  • Sandbox

Excel

  • Topics
  • All lessons
  • Cheat sheet
  • Shortcuts

HTML & CSS

  • Topics
  • All lessons
  • Cheat sheet

Touch typing

  • Topics
  • All lessons
  • Cheat sheet
  • Typing test

Lurndo

  • Dashboard
  • Leaderboard
  • Premium
  • Account
  • Blog
  • FAQ
  • Contact & support
  • Privacy
Nederlands