# Counting Alphabetic Characters in a String

by Allen Wyatt
(last updated January 20, 2020)

Shivram needs to count the number of times each letter of the alphabet occurs in a text string. For instance, if a cell contains the text "University of California at Santa Clara," he needs to know how many times the letter A is in the string, how many times the letter B, all the way to Z. He wonders what formula would he should use to do this.

One easy way to do this is to rely on the SUBSTITUTE function in your formula. You can use the function to remove whatever letter you are looking for from the text, and then compare the "before" and "after" lengths of the text.

Let's start by assuming you have the letters A through Z in the range A2:A27. In cell B1 you would put the text you want to analyze ("University of California at Santa Clara") and in cell B2 you would put this formula:

```=LEN(UPPER(B\$1))-LEN(SUBSTITUTE(UPPER(B\$1),UPPER(\$A2),""))
```

Copy the formula down in the remaining cells (B3:B27), and it represents the count of each letter that appears in the text in B1. You can, if you desire, put additional text strings to analyze in row 1, and then copy the range B2:B27 to the columns just below those other text strings.

Note that this formula makes no differentiation between uppercase and lowercase letters. In other words, the letter "A" in column A will match both "A" and "a" in the text in row 1. If you want the formula to be case sensitive, you would remove the UPPER function from the formula, thusly:

```=LEN(B\$1)-LEN(SUBSTITUTE(B\$1,\$A2,""))
```

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2985) applies to Microsoft Excel 2007, 2010, 2013, and 2016.

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

Disabling Track Changes Completely

Have you ever had problems with a document because you accidentally pressed a keyboard shortcut? The good news is that ...

Discover More

Starting Out Formulas

When you enter a formula from the keyboard, Excel only knows it is a formula if you start it with an equal sign. You can ...

Discover More

Strange Message about Others Making Changes in a Workbook

Have you ever tried to save a workbook, only to be notified that someone else has made changes in it? What if you are the ...

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)

Extracting a State and a ZIP Code

Excel is often used to process or edit data in some way. For example, you may have a bunch of addresses from which you ...

Discover More

Identifying Values that Don't Follow a Specific Pattern

When you store textual information in a worksheet, it can be helpful to figure out if that information follows a pattern ...

Discover More

Determining Winners, by Category

Do you need to determine the top three values in a range of columns? The techniques discussed in this tip will come in ...

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

2020-03-19 11:19:46

David A Czuba

Constantinou's 'solution to a potential problem' is just what I was looking for to count letters in a pangram. A pangram uses words that contain all 26 letters of the alphabet in a sentence. Together with a dictionary and code for finding words containing specific letters, a pangram generator could be made. That might seem like an esoteric problem, but it actually has application in cryptography, hashing and checksum calculations.

2016-06-06 08:56:06

JC

I don't understand the cheating complaint. Even though I find it interesting to attempt to derive such a formula myself, I personally "Google" such things frequently just to save time.

2016-06-06 07:20:34

Christos Constantinou

I could care less if it's a student class excercise. It's a solution to a potential problem and i took it one step further.
By placing the text in A2 and the alphabet in row 1 starting from B1 you can then place this formula
=LEN(\$A2)-LEN(SUBSTITUTE(UPPER(\$A2);B\$1;""))

in B2 and copy and paste it all the way to AA2. You now have the ability to import a text file with the option to "Fill down formulas in columns adjacent to data" marked and have Excel count the occurence of each letter in the whole document.

You'll need to add a column with the alphabet (Transpose row 1) and a SUM
next to each letter summing the corresponding column.

2016-06-05 18:01:06

Emmanuel Osafo Gyane

Wonderful code yet simple to write; thanks.

2016-06-04 11:14:39

Glenn Abel

Haha! You inspired me to play so I wrote a little workbook to calculate scrabble word values just for the nerdy fun of it.

Used http://www.wordfind.com/scrabble-letter-values/ to make a table to lookup values from, and made my list of letters by incrementing char(65), char(66), etc. to get A, B, etc.

I figured there were calculators out there, but that's not the point - just wanted to try out your tip. I found one and checked my work with http://www.dvorkin.com/scrabscor.php and proved my little calculator based on your tip was correct.

P.S. AllenWyatt has a Scrabble word score of 16. Have a nice day.

2016-06-04 09:41:14

Not Alex

This would not be the fastest way to cheat on a class exercise. There is a week between the published question and the published answer, not to mention the unknown delay between the student submitting their class exercise question to Alex and Alex deciding to answer it. Not to mention that only a percentage of questions received are even published.

2016-06-04 09:14:16

David de Jongh

This looks suspiciously like a student class exercise. Asking for the solution on a forum is essentially cheating.

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