Counting · About 5 minutes
COUNTIF with wildcards
Sometimes you want to count cells that only partly match. A wildcard is a symbol that stands in for other characters.
* (star) stands for any number of characters, even none. "Cotton*" matches anything that starts with Cotton, and "*saree" matches anything that ends with saree.
? (question mark) stands for exactly one character. "SAR-??" matches SAR-12 but not SAR-140. Capitals don't matter: "cotton*" works too.
Exercise 1 of 4 · Worked example
In B9, count the items made of cotton. Type =COUNTIF( A2:A7, "Cotton*") and press Enter.
| A | B | |
|---|---|---|
| 1 | Item | Code |
| 2 | Cotton kurta | KUR-101 |
| 3 | Silk saree | SAR-12 |
| 4 | Cotton saree | SAR-140 |
| 5 | Linen shirt | SHI-205 |
| 6 | Silk kurta | KUR-37 |
| 7 | Cotton dupatta | DUP-118 |
| 8 | ||
| 9 | Cotton items | (answer cell) |
Questions people ask
How do I count cells that contain specific text?
Put * on both sides: =COUNTIF( counts every cell with "tea" anywhere in it.
How do I count cells that do not contain a word?
Put <> before the pattern: =COUNTIF(.
What do * and ? mean in COUNTIF?
* stands for any number of characters, including none. ? stands for exactly one, so "???" matches any three-character text.
Why doesn't my wildcard match numbers?
Wildcards only match text. A code stored as a number, like 1045, is skipped by "10*".
How do I count cells that contain an actual asterisk?
Put a tilde before it: "*~**" counts cells that contain *.