What you will learn
- Count text that starts or ends with something
- Count text that contains something
How it works
"Red*"starts with Red"*Shirt"ends with Shirt"*Hat*"has Hat anywhere
Formulas at a glance
=COUNTIF(A2:A7,"Red*") | starts with |
=COUNTIF(A2:A7,"*Shirt") | ends with |
=COUNTIF(A2:A7,"*Hat*") | contains |
Example
Write the formula to count products that start with Red.
| A | B | C | |
|---|---|---|---|
| 1 | Product | ||
| 2 | Red Shirt | Starts with Red | |
| 3 | Blue Shirt | Ends with Shirt | |
| 4 | Red Hat | Has Hat | |
| 5 | Green Shirt | ||
| 6 | Blue Hat | Starts with Blue | |
| 7 | Red Socks | Ends with Socks |
Click D2 and type =COUNTIF(A2:A7,"Red*"), then press Enter.
The answer is 3.
When to use it
- Counting products in one color or style
- Counting names that start with a letter
- Counting entries that contain a word
Common mistakes
- Forgetting the star"Red" only matches exactly Red. Use "Red*".
- Putting the star on the wrong sideStar after = starts with. Star before = ends with.
- Expecting capitals to matterCOUNTIF ignores capital letters.
Practice it on a real sheet
Reading is a start. Doing it is how it sticks. This lesson walks you through every click on a live spreadsheet and checks each answer.