Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Counting Asterisks.

# Counting Asterisks

by Allen Wyatt
(last updated November 30, 2017)

David needs to count the number of asterisks that appear in a range of cells. He notes that COUNTIF appears to assume that * is a wild card character, so it doesn't return the proper count.

There are a number of ways to get results, based upon what it is you actually want to get. Let's assume that you have the following values in cells A3:A8:

• 1234
• abcd
• ab*cd
• ab*c*d
• *
• ***

In these six cells there are a total of seven asterisks. To determine the number of asterisks appearing within the range, you'll need to rely upon an array formula, such as this one:

```=SUM(LEN(A3:A8)-LEN(SUBSTITUTE(A3:A8,"*","")))
```

Remember to enter the formula with Ctrl+Shift+Enter.

Of course, you might want to count the number of cells in the range that contain a single asterisk instead of the number of actual asterisks. In this case you can actually use the COUNTIF function, provided you know how to put the formula together. First, try this formula:

```=COUNTIF(A3:A8,"*")
```

With the data shown at the beginning of this tip, this formula returns the value 5. This, of course, is wrong. The reason it returns this result is because COUNTIF uses * as a wildcard that means "any text in the cell." Since there are five cells in the range that contain text (non-numeric values), that is the answer returned by the formula.

You might think that if you searched for the ANSI character of the asterisk, instead of the asterisk itself, you could get the correct result. This formula shows this approach:

```=COUNTIF(A3:A8,CHAR(42))
```

This formula also returns the incorrect answer (5). It appears that Excel sees no difference, in application, between searching for * and searching for CHAR(42). Both are still treated as a wildcard.

The solution to this is to remember that you can force Excel to treat the asterisk as an actual character by preceding it with a tilde, character, in this manner:

```=COUNTIF(A3:A8,"~*")
```

This returns a result of 1, which may be surprising. Excel is very literal, however, and your formula asked for a count of all the cells which contain a single asterisk. The correct answer is that only one cell (A7) contains what you asked for. If you want to count all the cells that contain an asterisk anywhere within the cell, then you need to surround the formula with wildcard characters, in this manner:

```=COUNTIF(A3:A8,"*~**")
```

This returns "any text" followed by a literal asterisk followed by "any text." The result is 4, which is the number of cells that contain at least one asterisk.

The concept of using tildes to counteract wildcards is covered in this Knowledge Base article:

```http://support.microsoft.com/kb/214138
```

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9483) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Counting Asterisks.

##### Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

##### MORE FROM ALLEN

Opening Documents in Print Layout View

If you have a Word 2003 document that always seems to open in reading layout mode, you may want to turn that "feature" ...

Discover More

Specifying a Label Stock for Saved Documents

When you create a document designed to be printed on a particular type of label stock, it might be helpful if Word ...

Discover More

Create a Template that Stops Styles from Being Added to a Document

Limiting which styles a user can use or add to a document can be a tricky task. Fortunately, Word has advanced to the ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

##### More ExcelTips (ribbon)

When you are working with sequenced values in a list, you’ll often want to take some action based on the top X or ...

Discover More

Teachers often grade on what is affectionately referred to as "the curve." The problem is, it can be a bit difficult to ...

Discover More

Creating an Amortization Schedule

An amortization schedule is a report that shows how the outstanding balance on a loan changes with payments made over ...

Discover More
##### Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is three less than 5?

2017-06-09 06:04:08

Steve

Thank you for the tilde tip, solved my problem, very grateful

2016-12-07 15:52:59

Shar

This did not work for me

2016-06-28 10:46:26

Struan

Superb! Such a simple solution (*~**, but saved a lot of frustration. Thankyou

2016-04-05 13:41:19

Arjun

This is brilliant, just validates there are some many geniuses around.

2016-01-06 18:49:20

Carla

HI there
Have similar problem
data looks like this

gyne
gyne onco
gyne robot
gyne onco*
gyne*

need to count as follows:

gyne or gyne* = is the same
gyne onco and gyne onco* = is the same

But when i write countif(a1:a5,b1(which is gyne*) it does not count (gyne and gyne* only but everything that starts with gyne???

I think the problem is with the *. How can I fix this.

HOpe someone can help. Thanks

2015-11-03 22:45:29

Paul

Thanks for this - I couldn't fathom why my COUNTIF wouldn't count the instances of *** in a list (nor, while I'm at it, ===)but this tip saved my bacon 8-D

##### This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.