Count Specific Words in a Cell: Excel & Sheets
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
To count specific words in a cell in Excel or Google Sheets, use a formula that subtracts the length of the text without the word from the length of the original text, then divides by the word’s length. For example, to count “cat” in cell A1, enter =(LEN(A1)-LEN(SUBSTITUTE(A1,"cat","")))/3. This returns the number of times “cat” appears, even if it appears multiple times.
Formula
The formula counts how many times a specific word (or any substring) appears within a cell. It works by comparing the length of the original text to the length of the text after removing all instances of the word.
In symbols: Count = (LEN(text) - LEN(SUBSTITUTE(text, word, ""))) / LEN(word)
- LEN(text) – the number of characters in the original cell.
- SUBSTITUTE(text, word, “”) – replaces every occurrence of the word with an empty string, effectively deleting them.
- LEN(SUBSTITUTE(…)) – the number of characters left after deletion.
- LEN(word) – the number of characters in the word you’re counting.
The difference in lengths gives the total characters removed, and dividing by the word’s length gives the count of occurrences.
Worked Example
Using the default values from the calculator: text = “The quick brown fox jumps over the lazy dog”, word = “the”.
- Original length:
LEN("The quick brown fox jumps over the lazy dog")= 43 characters. - Remove all “the” (case-insensitive? No, the formula is case-sensitive, so “The” is not removed). Actually, the default word is lowercase “the”, and the text has “The” (uppercase T) and “the” (lowercase). The formula will only remove lowercase “the”.
- After removing lowercase “the”: “The quick brown fox jumps over lazy dog” – note the double space where “the” was. Length = 40.
- Difference = 43 – 40 = 3 characters.
- Divide by length of “the” (3) = 1.
So the formula returns 1, meaning “the” appears once (lowercase). The uppercase “The” is not counted because the formula is case-sensitive.
Case Sensitivity and Whole Words
The basic formula is case-sensitive. If you want to count “the” regardless of case, wrap both arguments in LOWER() or use SUBSTITUTE(LOWER(text), LOWER(word), ""). For example: =(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),LOWER("the"),"")))/LEN("the").
Also, the formula counts substrings, not whole words. So if you count “the” in “theater”, it will count one occurrence even though “the” is not a separate word. To count only whole words, you need a more complex formula, such as counting spaces around the word, or using a regular expression (in Google Sheets with REGEXEXTRACT or in Excel with VBA). A common workaround is to add spaces to the text and word: =(LEN(" "&A1&" ")-LEN(SUBSTITUTE(" "&A1&" "," "&word&" ","")))/LEN(word) – but this still fails if the word is at the start/end or followed by punctuation.
Counting in a Range
To count how many cells in a range contain a specific word, use COUNTIF. For example, =COUNTIF(A1:A10,"*cat*") counts cells that contain “cat” anywhere. To count total occurrences across multiple cells, you can sum the per-cell formula: =SUMPRODUCT((LEN(A1:A10)-LEN(SUBSTITUTE(A1:A10,"cat","")))/3).
Common Mistakes and Limitations
- Case sensitivity: Forgetting that the formula is case-sensitive leads to undercounting.
- Substring vs. whole word: Counting “cat” in “concatenate” gives 1, which may not be intended.
- Overlapping words: The formula cannot count overlapping occurrences (e.g., “aaa” in “aaaa” – it counts 1, not 2).
- Word length: If the word is empty, the formula divides by zero. Always ensure the word is not blank.
- Punctuation: “cat,” is not counted as “cat” because of the comma. You may need to clean the text first.
Alternatives for Complex Needs
If you need case-insensitive, whole-word counting, consider using a custom function in Google Sheets (Apps Script) or a VBA macro in Excel. For simple needs, the LEN/SUBSTITUTE method is fast and built-in. In Google Sheets, you can also use REGEXEXTRACT with a pattern like \bcat\b to find whole words, but counting multiple occurrences requires more work.
Frequently Asked Questions
How do I count a word ignoring case?
Use LOWER() on both the text and the word. Example: =(LEN(A1)-LEN(SUBSTITUTE(LOWER(A1),LOWER("cat"),"")))/LEN("cat"). This converts everything to lowercase before counting.
Why does my formula return a decimal?
If the word appears, the numerator is a multiple of the word length, so the result should be an integer. A decimal suggests the word isn’t found correctly, or the text contains different case or extra spaces. Check for trailing spaces in the word or text.
Can I count multiple different words at once?
Yes, you can add separate formulas for each word and sum them. For example, =(LEN(A1)-LEN(SUBSTITUTE(A1,"cat","")))/3 + (LEN(A1)-LEN(SUBSTITUTE(A1,"dog","")))/3.
How do I count words in a cell that are separated by spaces?
To count total words (not a specific word), use =LEN(TRIM(A1))-LEN(SUBSTITUTE(TRIM(A1)," ",""))+1. This counts spaces plus one.
Does this work in Google Sheets?
Yes, the same LEN and SUBSTITUTE functions work in Google Sheets. The formula is identical.
What if my word has special characters like * or ?
In Excel, SUBSTITUTE treats them as literal characters, so no problem. However, if you use COUNTIF with wildcards, * and ? are wildcards. For SUBSTITUTE, they are fine.
Related
Formula used
in t | Text | - | The quick brown fox jumps over the lazy dog | 0 in w | Word to count | - | the | 0 out count | Occurrences | count | (LEN(t)-LEN(SUBSTITUTE(t,w,"")))/LEN(w) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.