Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. 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 Cells with Specific Characters.

Counting Cells with Specific Characters

Written by Allen Wyatt (last updated October 10, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


8

Let's say that you have a worksheet that contains all the people who have ever worked in your department. Each name is prefaced by a single character that indicates the status of the person. For instance, if Fred Davis were retired, his name might show up as "RFred Davis". With quite a lot of these names in the worksheet, you may need a way to count those people with a specific status character.

The easiest way to accomplish this is to use the COUNTIF function. If, for instance, the status character is the letter R (for "retired"), and your range of names is in cells A5:A52, then you could use the following to determine which cells begin with the letter R:

=COUNTIF(A5:A52,"R*")

The formula works because the comparison value is R*, which means "the letter R followed by any other characters." Excel dutifully returns the count. To search for a different status character, simply replace R with the desired status character.

Obviously, if the asterisk has a special meaning in this usage, you can't search directly for an asterisk. Actually, there are three characters you cannot search for directly: the asterisk (*), the question mark (?) and the tilde (~). If you want to search for any of these characters, you must precede the character with the tilde. Thus, if you wanted to determine a count of names that had a question mark as a status code, you could use the following:

=COUNTIF(A5:A52,"~?*")

An alternative to using COUNTIF is to create an array formula that is applied to every cell in the range. The following will do the trick very nicely:

=SUM((LEFT(A5:A52,1)="R")*1)

This must, of course, be entered as an array formula. This means that instead of pressing Enter at the end of the formula, you would press Shift+Ctrl+Enter. The formula checks the left-most character of a cell, returning the value TRUE if it is R or FALSE if it is not. The multiplication is done to convert the TRUE/FALSE value to a number, either 1 for TRUE or 0 for FALSE. The SUM function returns the sum, or count, of all the cells that meet the criteria.

One final note: The formulas provided in this tip are a way to deal with the data as originally presented at the first of the tip. If you have any control at all over your data, you really should consider removing the "R" (or any other leading status character) from the names. Those sorts of characters really deserve their own column, instead of complicating the name field. Use the Text to Columns tool to separate out the "R" and any other leading characters, and then you can more easily work with them in your formulas.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9871) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Counting Cells with Specific Characters.

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

Printing a List of Custom Styles

You can add any number of styles to your document in order to define how you want your text to appear. If you later want ...

Discover More

Dealing with Oily Skin

Does your skin feel greasy to the touch and are you having problems getting just the right look with your facial makeup? ...

Discover More

Documents Marked as Security Risk

If your Word documents contain macros, it is possible that Word (or Windows itself) may block the use of those documents ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Deriving Antilogs

Creating math formulas is a particular strong point of Excel. Not all the functions that you may need are built directly ...

Discover More

Using a Numeric Portion of a Cell in a Formula

If you have a mixture of numbers and letters in a cell, you may be looking for a way to access and use the numeric ...

Discover More

Calculating the Median Age of a Group of People

Suppose you have a worksheet that contains a list of ages and then a count of people who correspond with those ages. You ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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}] (all 7 characters, in the sequence shown) 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 two more than 7?

2023-10-12 07:11:54

Philip

@J. Woolley, I didn’t mis that. In my example Robert would come out as a retired guy named obert …


2023-10-11 12:40:34

Tomek

@Philip and @J. Woolley,

Your comments just support the final statement from the tip. Having a prefix embedded in the name field just complicates the data and essentially requires a legend or other explanation. And keeping it up-to-date for anybody who will inherit this workbook after the original author is no longer available will be much harder.


2023-10-11 10:32:53

J. Woolley

@Philip
Perhaps you are missing the Tip's second sentence: "Each name is prefaced by a single character that indicates the status of the person."


2023-10-10 16:26:36

Philip

Unless I’m missing something, this tip offers an incomplete solution … a person named Robert would also be counted, retired or not. The COUNTIF should really test two conditions : the one from the tip AND the second character is uppercase (to eliminate Robert from the count)


2020-08-23 10:10:22

Peter Atherton

Amit
You need the Excel4 macro Evaluate. To make it work as a function you need to create a range name and put EValuate in the Refereernce cell.
Select B1
Press Ctrl + F3 (opens Name Manager) Click New
In the Name Type Eval
Make your that The scope is you active cell.
In the reference box type =EVALUATE(A1)
Click OK

For your formula Enter 1*2+3*2
In b1 type =Eval, this will return 8
You can put a function in any cell but the =Eval must be in the same row one column offset. For instance if d3 contains the functio SIN(1) E3 returns something like 57.xxx Degrees for 1 radian
Google VBA Evaluate aand you will find losts of links.


2020-08-22 11:12:06

Amit

How in ms excel sum of special characters value like 1(2)+3(2)=4(4)


2020-07-05 06:56:51

Nadeeshan Thisera

Tanx Sir........................


2020-04-07 03:46:47

Satyen

Hi,
I'm getting same count for R* and R.

Regards,


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.

Newest Tips
Subscribe

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

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.