by Svetlana Cheusheva, updated on

*The tutorial explains how to count words in Excel by using the LEN function in combination with other Excel functions, and provides case-sensitive and case-insensitive formulas to count total or specific words/text in a cell or range.*

Microsoft Excel has a handful of useful functions that can count nearly everything: the COUNT function to count cells with numbers, COUNTA to count non-blank cells, COUNTIF and COUNTIFS to conditionally count cells, and LEN to calculate the length of a text string.

Unfortunately, Excel doesn't provide any built-in tool for counting the number of words. Luckily, by combining serval functions you can make more complex formulas to accomplish almost any task. And we will be using this approach to count words in Excel.

To count words in a cell, use the following combination of LEN, SUBSTITUTE and TRIM functions:

LEN(TRIM(*cell*))-LEN(SUBSTITUTE(*cell*," ",""))+1

Where *cell* is the address of the cell where you want to count words.

For example, to count words in cell A2, use this formula:

`=LEN(TRIM(A2))-LEN(SUBSTITUTE(A2," ",""))+1`

And then, you can copy the formula down to count words in other cells of column A:

First, you use the SUBSTITUTE function to remove all spaces in the cell by replacing them with an empty text string ("") for the LEN function to return the length of the string without spaces:

`LEN(SUBSTITUTE(A2," ",""))`

After that, you subtract the string length without spaces from the total length of the string, and add 1 to the final word count, since the number of words in a cell equals to the number of spaces plus 1.

Additionally, you use the TRIM function to eliminate extra spaces in the cell, if any. Sometimes a worksheet may contain a lot of invisible spaces, for example two or more spaces between words, or space characters accidentally typed at the beginning or end of the text (i.e. leading and trailing spaces). And all those extra spaces can throw your word count off. To guard against this, before calculating the total length of the string, we use the TRIM function to remove all excess spaces except for single spaces between words.

The above formula to count words in Excel could be called perfect if not for one drawback - it returns 1 for empty cells. To fix this, you can add an IF statement to check for blank cells:

`=IF(A2="", 0, LEN(TRIM(A2))-LEN(SUBSTITUTE(A2," ",""))+1)`

As you can see in the screenshot above, the formula returns zero for blank cells, and the correct word count for non-empty cells.

To count how many times a certain word, text, or substring appears in a cell, use the following formula:

`=(LEN(`

*cell*)-LEN(SUBSTITUTE(*cell*, *word*,"")))/LEN(*word*)

For example, let's calculate the number of "*moon*" occurrences in cell A2:

`=(LEN(A2)-LEN(SUBSTITUTE(A2, "moon","")))/LEN("moon")`

Instead of entering the word to be counted directly in the formula, you can type it in some cell, and reference that cell in your formula. As a result, you will get a more versatile formula to count words in Excel.

Tip. If you plan on copying your formula to multiple cells, be sure to fix the reference to the cell containing the word to count with the $ sign. For example:

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

- The SUBSTITUTE function removes the specified word from the original text.

In this example, we remove the word input in cell B1 from the original text located in A2:

`SUBSTITUTE(A2, $B$1,"")`

- Then, the LEN function calculates the length of the text string without the specified word.

In this example,`LEN(SUBSTITUTE(A2, $B$1,""))`

returns the length of the text in cell A2 after removing all characters contained in all occurrences of the word "*moon*". - After that, the above number is subtracted from the total length of the original text string:

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

The result of this operation is the number of characters contained in all occurrences of the target word, which is 12 in this example (3 occurrences of the word "

*moon*", 4 characters each). - Finally, the above number is divided by the length of the word. In other words, you divide the number of characters contained in all occurrences of the target word by the number of characters contained in a single occurrence of that word. In this example, 12 is divided by 4 , and we get 3 as the result.

Apart from counting the number of certain words in a cell, you can use this formula to count the **occurrences of any text** (substring). For example, you can count how many times the text "*pick*" appears in cell A2:

As you probably know, Excel SUBSTITUTE is a case-sensitive function, and therefore the word counting formula based on SUBSTITUTE is case-sensitive by default:

If you need to count both uppercase and lowercase occurrences of a given word, use either the UPPER or LOWER function inside SUBSTITUTE to convert the original text and the text you want to count to the same case.

=(LEN(*cell*)-LEN(SUBSTITUTE(UPPER(*cell*),UPPER(*text*),"")))/LEN(*text*)

Or

=(LEN(*cell*)-LEN(SUBSTITUTE(LOWER(*cell*),LOWER(*text*),"")))/LEN(*text*)

For example, to count the number of occurrences of the word in B1 within cell A2 ignoring case, use this formula:

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

As demonstrated in the below screenshot, the formula returns the same word count regardless of whether the word is typed in UPPERCASE (cell B1), lowercase (cell D1) or Sentence case (cell C1):

To find out how many words a certain range contains, take the formula that counts total words in a cell and embed it within either SUMPRODUCT or SUM function:

=SUMPRODUCT(LEN(TRIM(*range*))-LEN(SUBSTITUTE(*range*," ",""))+1)

Or

=SUM(LEN(TRIM(*range*))-LEN(SUBSTITUTE(*range*," ",""))+1)

SUMPRODUCT is one of few Excel functions that can handle arrays, and you complete the formula in the usual way by pressing the Enter key.

For the SUM function to calculate arrays, it should be used in an array formula, which is completed by pressing Ctrl+Shift+Enter instead of the usual Enter stroke.

For example, to count all words in range A2:A4, use one of the following formulas:

`=SUMPRODUCT(LEN(TRIM(A2:A4))-LEN(SUBSTITUTE(A2:A4," ",""))+1)`

`=SUM(LEN(TRIM(A2:A4))-LEN(SUBSTITUTE(A2:A4," ",""))+1)`

If you want to count how many times a particular word or text appears within a range of cells, use a similar approach - take the formula to count specific words in a cell, and combine it with the SUM or SUMPRODUCT function:

=SUMPRODUCT((LEN(*range*)-LEN(SUBSTITUTE(*range*, *word*,"")))/LEN(*word*))

Or

=SUM((LEN(*range*)-LEN(SUBSTITUTE(*range*, *word*,"")))/LEN(*word*))

Please remember to press Ctrl+Shift+Enter to correctly complete the array SUM formula.

For example, to count all occurrences of the word entered in cell C1 within the range A2:A4, use this formula:

`=SUMPRODUCT((LEN(A2:A4)-LEN(SUBSTITUTE(A2:A4, C1,"")))/LEN(C1))`

As you remember, SUBSTITUTE is a **case-sensitive** function, and therefore the above formula distinguishes between uppercase and lowercase text:

To make the formula **case-insensitive**, use either the UPPER or LOWER function:

`=SUMPRODUCT((LEN(A2:A4)-LEN(SUBSTITUTE((UPPER(A2:A4)),UPPER(C1),"")))/LEN(C1))`

Or

`=SUMPRODUCT((LEN(A2:A4)-LEN(SUBSTITUTE((LOWER(A2:A4)),LOWER(C1),"")))/LEN(C1))`

This is how you count words in Excel. To better understand and probably reverse-engineer the formulas, you are welcome to download the sample Excel Count Words workbook.

If none of the formulas discussed in this tutorial has solved your task, please check out the following list of resources that demonstrate other solutions to count cells, text and individual characters in Excel.

Table of contents