=LEN(a1)-LEN(SUBSTITUTE(a1,txt,""))

To count how many times a specific character appears in a cell, you use a formula based on the SUBSTITUTE and LEN functions. In the generic form of the formula above, a1 represents the cell address, and txt represents the character(s) that you want to count.

In the example, the active cell contains this formula:

=LEN(B3)-LEN(SUBSTITUTE(B3,C3,""))## How this formula works

This formula works by using SUBSTITUTE to first remove all of the characters being counted in the source text. Then the length of the text (with the character removed) is subtracted from the length of the original text. The result is the number of characters that were removed with SUBSTITUTE, which is equal to the count of those characters.

## Upper and lower case

SUBSTITUTE is a case sensitive function, so it will match case when running a substitution. If you need to count both upper and lower case occurrences of a specific character, use the UPPER function inside SUBSTITUTE to convert the text to uppercase before running the substitution. Then supply an uppercase character as the text that’s being substituted.

=LEN(B3)-LEN(SUBSTITUTE(UPPER(B3),C3,""))