Counting Alphabetic Characters in a String

Written by Allen Wyatt (last updated May 28, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


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, 2016, 2019, Excel in Microsoft 365, and 2021.

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

Applying Bullets from the Keyboard

Most people use the toolbars to apply bullets to paragraphs. If you want to apply them using the keyboard, then you can ...

Discover More

Ignoring the Spelling of Proper Nouns

Proper nouns (such as the names of people) are routinely marked as incorrect by Word's spell checker. If you are tired of ...

Discover More

Searching for Styles

If you use styles to format your text, you can later search for words and phrases that are formatted using various ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (ribbon)

Putting Amounts in Month Columns

Sometimes putting together a formula can be a challenge. Part of the process, though, is examining the data with which ...

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

First Value Less Than or Equal to 100

If you need to evaluate a row of values to meet specific criteria, then you'll appreciate the discussion in this tip. It ...

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