# Counting Alphabetic Characters in a String

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,""))
```