EXCEL & GOOGLE SHEETS TIPS · LESSON 5
How to Use COUNTIF in Excel and Google Sheets (Count Cells With Text)
COUNTIF counts the cells that match a condition: days a habit was done, invoices marked "Paid", trades that won, cells that contain any text at all. This lesson turns a real November habit log into a scoreboard in Excel and Google Sheets, explains the "*" trick for counting text, shows COUNTIFS for two conditions and fixes the counts that come out wrong.
THE SHORT ANSWER
Two arguments: where to look and what to count
=COUNTIF(C2:C31, "Yes")Count the cells in C2:C31 that say Yes. Upper or lower case doesn't matter.Click the result cell → type =COUNTIF( → select the range → comma → type the condition in quotes ("Yes", ">=30", "*") or click a cell → ) → Enter.
Exactly the same: =COUNTIF(range, criterion). For several conditions in the same row use =COUNTIFS(range1, criterion1, range2, criterion2) in both apps.
The example is a habit log for November 2026: one row per day, Walk, Read and Water marked Yes or No with a drop-down list (lesson 1), green and red by conditional formatting (lesson 3), and minutes read. Days 26 to 30 are still empty, which is exactly where counting gets tricky. Download the example file (Excel; it also opens in Google Sheets).
EXCEL
How to use COUNTIF in Excel
- Click the result cell, J2 next to "Walk", and type
=COUNTIF(. - Select the range to look at, C2:C31 (the Walk column for the whole month), and type a comma.
- Type the criterion in quotes:
"Yes". Text and comparisons always go in quotes; a cell reference doesn't. - Close the bracket and press Enter. J2 shows 20: the walk was done on 20 days.
COUNT CELLS WITH TEXT
Count cells that contain any text: the "*" criterion
A success rate needs two numbers: days done and days tracked. Days tracked are the cells with anything typed in them, Yes or No, but not the empty days at the end of the month. The asterisk is a wildcard for "any text":
=COUNTIF(C2:C31, "*")Counts every cell in C2:C31 that holds text. Empty cells and numbers are not counted. Result: 25 tracked days.
=J2/K2 formatted as a percentage: 20 / 25 = 80%.Not sure what a criterion matches? Click fx next to the formula bar: the Formula Builder shows each argument and the result before you confirm.
| Formula | Counts | In the example |
|---|---|---|
=COUNTIF(C2:C31,"*") | Cells with text | 25 |
=COUNTA(C2:C31) | Cells that are not empty (text, numbers, errors) | 25 |
=COUNT(F2:F31) | Cells with numbers only | 25 (minutes read) |
=COUNTBLANK(C2:C31) | Empty cells | 5 (Nov 26 to 30) |
=COUNTIF(C2:C31,"?*") | Text with at least one character | 25 |
=IF(B2="","",…)) leaves a cell that looks blank but holds text of length zero. "*" may count those; "?*" requires at least one real character. Use "?*" when your columns are filled by formulas.COUNTIFS
COUNTIFS: count rows that meet two conditions
"How many weekend walks?" needs two tests in the same row: the day is Saturday (or Sunday) and Walk is Yes. COUNTIFS takes pairs of range and criterion; every pair must be true. Saturday and Sunday are two separate counts added together, because one criterion can't say "Sat or Sun":
=COUNTIFS(B2:B31, "Sat", C2:C31, "Yes") + COUNTIFS(B2:B31, "Sun", C2:C31, "Yes")Result: 6 weekend walks out of 7 weekend days logged.
=COUNTIF(F2:F31,">=30") = 6 days.All ranges in COUNTIFS must be the same size (B2:B31 and C2:C31), or you get #VALUE!. COUNTIFS works in Excel 2007 and later and in Google Sheets.
GOOGLE SHEETS
How to use COUNTIF in Google Sheets
Type =COUNTIF( and Sheets shows the help card COUNTIF(range, criterion) with the current argument highlighted; the label above the cell previews the result (20) before you press Enter.
=COUNTIF(C2:C31, TRUE), without quotes.COPY AND ADAPT
COUNTIF criteria cheat sheet
| Count cells that… | Formula |
|---|---|
| equal a word | =COUNTIF(C2:C31, "Yes") |
| equal the value in a cell | =COUNTIF(C2:C31, H2) |
| are not a word | =COUNTIF(C2:C31, "<>No") (includes blanks) |
| contain a word anywhere | =COUNTIF(B2:B100, "*invoice*") |
| start with text | =COUNTIF(B2:B100, "INV-*") |
| are greater than or equal to a number | =COUNTIF(F2:F31, ">=30") |
| are greater than a cell | =COUNTIF(F2:F31, ">"&H1) |
| fall in a date range | =COUNTIFS(A2:A31, ">="&DATE(2026,11,1), A2:A31, "<="&DATE(2026,11,15)) |
| are unique values (count each once) | =COUNTA(UNIQUE(FILTER(C2:C100, C2:C100<>""))) (Microsoft 365, Excel 2021+, Sheets; FILTER drops blanks, which UNIQUE would count as one more value). Google Sheets also has =COUNTUNIQUE(C2:C100). |
| appear more than once | =COUNTIF($B$2:$B$100, B2)>1 (see lesson 7) |
To add the numbers instead of counting the rows, swap in SUMIF with the same criteria: lesson 4 (SUMIF and SUMIFS).
TROUBLESHOOTING
COUNTIF not counting correctly?
| What you see | Why | Fix |
|---|---|---|
| 0 for text you can see | Extra spaces ("Yes ") or a different word ("Y", "Done"). | Clean with TRIM; use a drop-down so entries are identical. Case doesn't matter. |
| "*" misses numbers | "*" counts text only; 30 is a number. | Use COUNTA for any non-empty cell, COUNT for numbers. |
| Blank-looking cells are counted | Formulas returning "" or cells with a space. | Use "?*" for formulas returning ""; a cell holding a space still counts, so for those use =SUMPRODUCT(--(LEN(TRIM(C2:C31))>0)). |
| Number criterion returns 0 | The cell reference is inside the quotes: ">=H1", or the numbers are stored as text. | Join with &: ">="&H1; convert text numbers (Excel: Convert to Number; Sheets: VALUE). |
| Counts change when copied down | Ranges without $ slid down. | Lock shared ranges: $C$2:$C$31. |
| #VALUE! from COUNTIFS | The ranges are different sizes. | Make every range cover the same rows. |
| Need case-sensitive count | COUNTIF ignores case. | =SUMPRODUCT(--EXACT(C2:C31,"Yes")). |
FAQ
COUNTIF questions
How do I count cells with specific text?
Use =COUNTIF(range, "text"), for example =COUNTIF(C2:C31, "Yes"). To count cells that contain the text anywhere, add asterisks: =COUNTIF(B2:B100, "*invoice*").
What is the formula to count cells with any text?
=COUNTIF(range, "*") counts every cell that contains text. Use =COUNTIF(range, "?*") if formulas return empty text, and COUNTA to count numbers as well.
How do I use COUNTIF with two conditions?
Use COUNTIFS with pairs of range and criterion: =COUNTIFS(B2:B31, "Sat", C2:C31, "Yes") counts rows where B is Sat and C is Yes. For "either/or", add two COUNTIF or COUNTIFS results.
Does COUNTIF work in Google Sheets?
Yes, with the same syntax: =COUNTIF(range, criterion). COUNTIFS, COUNTA and COUNTBLANK work too.
Is COUNTIF case-sensitive?
No. "yes", "Yes" and "YES" are all counted. For a case-sensitive count use =SUMPRODUCT(--EXACT(range, "Yes")).
How do I count non-blank cells?
Use =COUNTA(range) for any non-empty cell, or =COUNTIF(range, "<>") which counts cells that are not empty.