Written by Allen Wyatt (last updated June 10, 2020)
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.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
When you need to count a number of cells based upon a single criteria, the standard function to use is COUNTIF. This tip ...
Discover MoreWhen you use Excel as a simple database program to store individual records, you may have a need to count the records ...
Discover MoreNeed 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 MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-11-26 12:28:52
ROY
Liz, you can use SUBSTITUTE() and LEN() to achieve that:
Say you are looking for "B", "L", and "c" in cell A1:
=( (LEN(A1) - LEN( SUBSTITUTE(A1, "B", "")) + (LEN(A1) - LEN( SUBSTITUTE(A1, "L", "")) + (LEN(A1) - LEN( SUBSTITUTE(A1, "c", "")) )
It will NOT yield an error if the count is zero for a letter so no need for error handling.
(SUBSTITUTE() is case sensitive so it will distinguish between "B" and "b" and so on. As the saying goes though: "However it is case sensitive so...": you must watch case, or allow for it, when entering the letters, which is easier if you do the following.)
It is also happy to accept cell references for the search text (the letters) so you can have an easily changed list of letters to check for. NOT a RANGE of references in a one-third of the above formula, but individual cell references. If you do that, you can watch for some entry errors like they should all be upper case or lower case by wrapping the reference in the applicable function:
SUBSTITUTE( A1, UPPER( N7 ), "")
Also worth mentioning while using SUBSTITUTE(), there are quite a few uses that compare a cell/string length before and after using SUBSTITUTE().
2018-03-06 12:55:59
Liz
In the same column I need to count multiple different letters to make one total of the different letters. Any assistance would be helpful!
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2023 Sharon Parq Associates, Inc.
Comments