Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Counting Cells with Specific Characters.

Counting Cells with Specific Characters

Written by Allen Wyatt (last updated December 23, 2023)
This tip applies to Excel 97, 2000, 2002, and 2003


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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2342) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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

Protecting Excel Files from Word

Office easily allows you to use Word to open an Excel document. Doing so, however, can quickly result in and unusable ...

Discover More

Applying Conditional Formatting to Multiple Worksheets

If you just updated your copy of Excel, you may have noticed some differences in how the program handles applying ...

Discover More

Calculating Page Count for a Range of Sections

When adding page numbers to a header or footer, you may find it helpful to modify how Word determines its "Page X of Y" ...

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 (menu)

An Average that Excludes Zero Values

Excel allows you to use functions and formulas to analyze your data. One way you can analyze your data is to use the ...

Discover More

Finding the Lowest Numbers

Need to find the lowest numbers in a range of values? It's easy to do using the SMALL worksheet function, or you can use ...

Discover More

Median of Selected Numbers

Need to find a median value in a series of values? It's easy with the MEDIAN function. What isn't as easy is to derive ...

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 6 + 5?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.