Excel and Google Sheets how-to
Count cells that contain text
A stock list where some items have a note and most do not. One COUNTIF with an asterisk counts the notes and skips the empty cells.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Item | Count | Note | Notes | |
| 2 | Pens | 40 | 3 | ||
| 3 | Paper | 12 | Reorder | ||
| 4 | Ink | Ask supplier | |||
| 5 | Tape | 8 | |||
| 6 | Labels | Reorder soon | |||
| 7 | Staples | 25 |
Sample data. Items in A, counts in B, notes in C, the formula in E2.
The formula
Click E2 and type:
=COUNTIF(C2:C7,"*")E2 shows 3: three items have a note. Empty cells are skipped.
- C2:C7 is the range to count in.
- "*" is a wildcard that matches any text at all.
Text, numbers or anything
COUNTA counts every cell that is not empty, text or number:
=COUNTA(B2:B7)That gives 4 on the Count column. COUNT counts only numbers, so =COUNT(B2:B7) also gives 4, and =COUNTBLANK(B2:B7) counts the empty cells: 2 (Ink and Labels). When a column mixes text and numbers and you want the text only, ISTEXT never counts a number:
=SUMPRODUCT(--ISTEXT(B2:B7))That gives 0 on the Count column and 3 on the Note column. The -- turns each TRUE into 1 and each FALSE into 0, and SUMPRODUCT adds them up.
Cells that contain a word
Put the word between two asterisks:
=COUNTIF(C2:C7,"*reorder*")That gives 2: "Reorder" and "Reorder soon". Capitals do not matter. Without the asterisks, =COUNTIF(C2:C7,"Reorder") gives 1, only the cell that is exactly Reorder. To use a word typed in another cell, say G2:
=COUNTIF(C2:C7,"*"&G2&"*")Starts with or ends with
One asterisk at the end means "starts with":
=COUNTIF(A2:A7,"P*")That gives 2, Pens and Paper. One at the start means "ends with": =COUNTIF(C2:C7,"*soon") gives 1. A question mark stands for exactly one character, and a tilde before * or ? counts the symbol itself: =COUNTIF(C2:C7,"*~?*") counts notes with a question mark in them.
Text that is not a certain word
This looks right but counts the empty cells too:
=COUNTIF(C2:C7,"<>Reorder")It gives 5, because a blank cell is also "not Reorder". Add the asterisk as a second condition to count only notes that are something else:
=COUNTIFS(C2:C7,"*",C2:C7,"<>Reorder")That gives 2: Ask supplier and Reorder soon.
The count is higher than the notes you see
A cell with only a space in it looks empty but holds text, so COUNTIF and COUNTA count it. Check a cell that looks empty:
=LEN(C2)0 means truly empty, 1 means one space. Select those cells and press Delete to clear them. COUNTIF, COUNTIFS, COUNTA, COUNT, COUNTBLANK and LEN work in every current version of Excel and in Google Sheets.
Templates with the math already done
Rather skip the formulas? These templates come with every formula built and checked, plus a filled-in sample.
- Inventory SpreadsheetList your items once, log stock in and out, and see what to reorder.
- Task Tracker SpreadsheetOne row per task with the owner, priority, status and due date.
- Wedding Checklist SpreadsheetEvery wedding task in one place, from 12+ months out to the thank-you notes.
More how-tos
- Find a price by its code with XLOOKUPType a product code, get its price back from your price list. One formula, no helper columns.
- Total each category with SUMIFSAdd up all the Fuel, all the Office, all the Meals: one formula per category, and more rules when you need them.
- Check two conditions at once with IF and ANDFree shipping only when the order is 50 or more and ships in Canada: one IF, one AND, done.
- Add leading zeros to numbersType 00021 and Excel or Google Sheets shows 21, because to them it is just the number 21. Here is how to get the zeros back, and keep them.
- Fix #DIV/0! in an averageAn average of nothing is a division by zero, so AVERAGE shows #DIV/0! until the first number arrives. One IF fixes it.
- Count rows that meet two conditions with COUNTIFSHow many of Ana's deals were 500 or more? COUNTIFS answers it in one cell, and takes as many rules as you need.
- Calculate percentage changeSales went from 400 to 500. That is a 25% increase, and one short formula works it out for every row.
- Calculate years of service from a start dateAna started on 15 March 2019. How many full years has she worked? DATEDIF counts them, and the same formula works out an age from a date of birth.
- Combine first and last name into one cellFirst names in one column, last names in the next, and you need "Ana Lopez" in one cell. The & sign joins them.
- Find duplicates in a list with COUNTIFA mailing list where some people signed up twice. One formula shows how many times each email appears, so the repeats stand out.
- Split a full name into first and last nameYour list has "Ana Lopez" in one cell and you need Ana and Lopez in two. Two short formulas find the space and split there.
- Total amounts by month with SUMIFSA list of dated expenses and you want one total per month. SUMIFS adds every amount between the first and the last day of the month.
- Count working days between two datesAna is off from 1 Oct to 14 Oct. How many working days is that? NETWORKDAYS counts Monday to Friday and leaves out the weekends.
- Hide #N/A in VLOOKUP with IFERRORYour order list has a code that is not in the price list, and VLOOKUP shows #N/A. IFERROR puts your own words there instead.
- Free pricing calculatorsPrice a job from your real costs and margin. No sign up.






