ExcelUnpackUnpack Excel, one formula at a time.
Log inSign up

Lesson 19 · Count functions

COUNTIF with wildcards in Excel

A star * stands for any letters. "Red*" matches anything that starts with Red, "*Shirt" anything that ends with Shirt, and "*Hat*" anything with Hat in it.

Practice this lesson →Pro lesson. The first 4 lessons are free.

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.

ABC
1Product
2Red ShirtStarts with Red
3Blue ShirtEnds with Shirt
4Red HatHas Hat
5Green Shirt
6Blue HatStarts with Blue
7Red SocksEnds 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.

COUNTIF with wildcards in Excel: how it works, with examples · ExcelUnpack