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 Cells with Specific Characters.

# Counting Cells with Specific Characters

by Allen Wyatt
(last updated October 14, 2019)

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 sort 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, and 2013. 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

Calculating Statistical Values on Different-Sized Subsets of Data

Discovering different ways to analyze your data can be a challenge. Here's how to work with arbitrary subsets of a large ...

Discover More

Printing Based on Cell Contents

Would you like to have a worksheet automatically printed when a particular cell contains a specified value? You can ...

Discover More

Understanding Variables in VBA Macros

You can create and use all sorts of variables in your macros. This tip examines all the different data types you can specify.

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)

Combining Cell Contents

Excel allows you to easily combine text together. Interestingly, it provides two ways you can perform such combinations. ...

Discover More

Functions that Can Access Closed Workbooks

When creating a workbook, you can include formulas that reference data stored in other workbooks. Some functions will ...

Discover More

Summing Every Fourth Cell in a Row

Need to sum a series of cells that fits some regular pattern? Here are several ways that you can get the summation that ...

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 2 + 8?

2019-10-15 02:41:10

steveJez

Ann,
If your data is - J1234AA another brick in the wall - in B3 use the formula =SUBSTITUTE(B3," ","@",1) to replace only the first space with the @ symbol, or whatever you like. This will find the first space regardless if it's 3 characters or 30 characters in.

HTH

2019-10-14 11:02:41

Ann

This kind of hits on something I tried to do last week. I am trying to take file directory info in three different areas and make it into one searchable record. I got my "listmyfolder.txt" files at the command prompts for each folder. I can parse that into columns where there are delineations, but the main title of the subfolders are, by company convention, the job number and the title. Job numbers are J plus usually four digits (the oldest are three) then one or two letters, and possibly a numeral at the end if it's a supplemental. So I can't use width to get a clean break between the numbers and the titles, since they vary. Is it possible to formulate: If any of the first eight or nine characters is a space, replace that space only with a distinct character (I usually use the @ symbol), so that I can then parse text to columns on only that spot and not every space in the title? I ended up parsing on every space, then concatenating the remaining text back together, which was a bit of a pain. The only other way I could think of was doing multiple searches, eliminating the most common ones that would be J, four digits, and ending in a G, an E, or a GE, and adding the @ to those, then sorting out any of the lines that didn't conform to one of those, and doing them manually.

2018-01-28 08:01:05

Peter Atherton

Subhash

I'm still using 2007 so this uses a UDF to get the cell formula. Later versions have a formula that does this CELLTEXT ?? possibly. You can use this function in place of CellF

=LEN(PERSONAL.XLSB!cellF(D3))-LEN(SUBSTITUTE(PERSONAL.XLSB!cellF(D3),"+",""))+1

On the chance that you are using an old version of Excel, here is the UDF

Public Function cellF(ByVal ref) As String

If ref.HasArray = False Then
cellF = ref.Formula
Else
cellF = "{" & ref.Formula & "}"
End If
End Function

2018-01-27 13:59:03

Subhash

Hi I add number in one cell like. =50+71+89+90+67+63 it become 430 cell appears 430 number .how can I know how many " + " in this cell.

2017-08-17 05:01:52

Peter therton

Kris
=SUM((LEFT(A5:A52,2)="EC")*1)

or to get both together
=SUM((LEFT(A5:A52,2)={"EC","EV"})*1)

2017-08-15 17:00:44

kris

I am trying to use the SUM formula above. I want to be able to tally how many cells have one of 5 selections from a dropdown . I can use this formula on 3 of them, because the words start with diff letters (S,T,P), but the other two selections both start with an "E". How might I adapt this formula to include the first 2 letters of each dropdown selection? That would get me the tallys for the 2 different "E" selections (EV* and EC*). Thank you in advance!!

2017-07-21 04:18:57

Peter

Ken

Try this Array formula

=SUM(IF(MID(A17:A20,2,1)=C18,1,"")) (enter with Ctl + Shift + Enter)

where c18 contains the letter to look for.

2017-07-20 17:25:09

ken

looking to calculate the sum of names that would have the same second letter on an excel spread sheet

2016-09-27 14:19:37

jagdish

I wish to count " ?" and "!" two punctuation marks from text of rows. Using your above formula =COUNTIF(A5:A52,"~?*") . I could not get the desired results.
Here I am just pasting records (2 rows).

(i) A phase II clinical study of interl(ii) Cancer stages: What do Chinese cancer patients know? Final safety and efficacy data for Asian patients (pts) in the MO19390 (SAiL) trial: First-line bevacizumab (Bv) plus chemotherapy in advanced or recurrent non-small cell lung cancer (NSCLC).

Kindly inform where I am committing mistake. I put these text in column A then put = in column B and use the above formula by selecting the range.

thanks,

Mr. Jagdish

2015-08-27 07:15:38

balthamossa2b

@Dave

Step 1 of IT: always assume there will be errors. Most of these caused by users.

2015-08-24 03:27:20

Bunio

I think it would be useful to benefit from SUMPRODUCT Excel function.
Namely:
SUMPRODUCT(+LEFT(LEFT(A5:A52,1)="R")*1)
Two remarks:
- "+" or "--" before LEFT is necessary to trigger evaluation in a "numeric" mode
-this approach does not require formula mode.

I have tested it on Polish version
=SUMA.ILOCZYNÓW(+(LEWY(B4:B7;1)="q")*1),
I hope I have transformed correctly to the English one.

2015-08-22 10:05:40

Dave H.

Refer to the second sentence of this article - "Each name is prefaced by a single character that indicates the status of the person." - Thus their name would have some leading character such as "A" (for Active), "T" (for Temporary), "R" (for Retired) etc. So names would be listed as "ARobert", "TRobert", "RRobert", etc. Their should never be an instance where their name would be listed as simply "Robert".

2015-08-22 07:39:45

Peter Curtis

What happens if the person's name is Robert or Roger and they are not retired?

##### 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.