Start practice

COUNTIF

AI for Excel ·

COUNTIF counts how many cells in a range meet one condition: how many orders came from the West, how many invoices are over $1,000, how many tasks are marked Done. For several conditions at once there is COUNTIFS. Both are simple, and both are easy to get slightly wrong.

Syntax

Formula
=COUNTIF(range, criteria)
  • range: the cells to test, for example C2:C9.
  • criteria: the condition: a value ("West"), a comparison (">1000") or a cell (H1).

For several conditions:

Formula
=COUNTIFS(criteria_range1, criteria1, criteria_range2, criteria2, ...)

Examples

The examples use this sheet, data in rows 2 to 9:

RowC RegionD ProductE AmountF Status
2WestLaptop1200Paid
3EastMonitor300Open
4WestMonitor250Paid
5NorthLaptop1100Paid
6EastLaptop1300Open
7WestKeyboard80Paid
8NorthMonitor280Open
9WestLaptop1150Paid

Count text

Question: how many orders came from the West?

Formula
=COUNTIF(C2:C9,"West")

Result: 4. COUNTIF is not case sensitive, so "west" works too, but "West " with a trailing space in the cells does not match.

Count above a number

Question: how many orders were over $1,100?

Formula
=COUNTIF(E2:E9,">1100")

Result: 3 (1,200, 1,300, 1,150). For "$1,100 or more", use ">=1100", which gives 4.

Two conditions with COUNTIFS

Question: how many West orders are paid?

Formula
=COUNTIFS(C2:C9,"West",F2:F9,"Paid")

Result: 4. All four West orders are paid. For open orders over $250: =COUNTIFS(F2:F9,"Open",E2:E9,">250") gives 3.

Condition in a cell

With 1000 in H1:

Formula
=COUNTIF(E2:E9,">"&H1)

Result: 4. Join the operator and the cell with &.

Variants

GoalCriteriaResult on the sheet
Equal to text"Laptop"4
Not equal"<>Laptop"4
Starts with"Mon*"3
Greater than">1000"4
Less than or equal"<=300"4
Not empty"<>"8

To count blank cells use COUNTBLANK, and to count all cells with numbers use COUNT.

COUNTIF with AI

COUNTIF is one of the formulas people ask AI for most, and one of the easiest to get slightly wrong, because the wording of the goal decides the operator. A good request names the column, the rows and the exact condition:

Prompt
In Excel, column E has order amounts in rows 2 to 9. Give me a formula that counts orders of $1,100 or more. Explain it in one line.

The answer should be =COUNTIF(E2:E9,">=1100"). If it comes back with ">1100", the words "or more" were lost on the way. Read the operator in every counting formula the AI gives you, and test it on the sheet: here the order of exactly 1,100 decides between 3 and 4. More on asking well in AI Excel formula generator.

Counting between two numbers

COUNTIF takes one condition, so a range like "between $250 and $1,200" needs COUNTIFS with the same column twice:

Formula
=COUNTIFS(E2:E9,">=250",E2:E9,"<=1200")

Result on the sheet: 6 (1,200, 300, 250, 1,100, 280 and 1,150). Only 1,300 and 80 fall outside.

Common errors

Count is too low by one or two

Usually > where the goal meant >=. "Over" and "more than" are >, "at least" and "or more" are >=.

Count is 0

The text does not match exactly: an extra space, a different spelling, or the range is the wrong column. Check one cell by hand. More in Excel formula not working.

Comparison written without quotes

=COUNTIF(E2:E9,>1000) is an error. The comparison goes in quotes: ">1000".

Counting numbers stored as text

Numbers that came from an export may be text. ">1000" will not count them. Convert the column to numbers first.

Using COUNTIF where a sum was asked

"How much did West sell" is a sum, not a count. Use SUMIFS for totals.

Practice

In the level "Write it yourself" you type COUNTIF and other formulas yourself on a realistic sheet. Each formula is checked on the sheet and on changed copies, so a formula that is right only by chance does not pass. To get faster, also practice getting formulas from AI and checking them.

Start step by step: Write it yourself

Free, in your browser, no sign up. Opens level “Write it yourself”.

FAQ

How do I use COUNTIF for greater than?

Put the comparison in quotes: =COUNTIF(E2:E9,">1000"). For a value in a cell: =COUNTIF(E2:E9,">"&H1).

What is the difference between COUNTIF and COUNTIFS?

COUNTIF tests one condition. COUNTIFS tests several, and counts only rows that meet all of them.

Can COUNTIF count text?

Yes. =COUNTIF(C2:C9,"West") counts cells that say West. Use wildcards like "*ship*" to count cells that contain a word.

How do I count cells between two numbers?

Use COUNTIFS with the same range twice: =COUNTIFS(E2:E9,">=250",E2:E9,"<=1200").

Is COUNTIF case sensitive?

No. "WEST", "West" and "west" are counted the same.

For learning only. Nothing here is legal, financial or tax advice. Sample AI replies in the practice are written in advance, and all names and numbers are made up.