Use =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 to count the words in cell A2.
=LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1
You often need to count words in Excel when you review text for length limits, such as a product description that must stay under 50 words, or when you analyze survey answers. Excel has no built-in word count function, but you can build one with a simple formula.
Step by step
- Select the cell where you want the word count to appear, for example B2 next to your text in A2.
- Type the formula
=LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1and press Enter. - The cell shows the number of words in A2.
- To count words for more cells, drag the fill handle down from B2.
- If you want to count words in a whole range, use
=SUMPRODUCT(LEN(TRIM(A2:A10))-LEN(SUBSTITUTE(TRIM(A2:A10)," ",""))+1)instead.
Try it here
Examples
1 Count words in one cell
The formula removes extra spaces with TRIM, then counts spaces by comparing the length of the text with and without spaces. Adding 1 gives the word count. For "Excel is fun" it returns 3.
| A | B | C | |
|---|---|---|---|
| 1 | Text | ||
| 2 | Excel is fun | 3 | |
| 3 | Learn Excel fast | ||
| 4 | Hello world | ||
| 5 | One | ||
| 6 | Two words | ||
| 7 | Three word phrase | ||
| 8 | Four words in here | ||
| 9 |
=LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+12 Count words in a range
SUMPRODUCT applies the word-count logic to each cell in A2:A4 and adds the results. It returns the total number of words in the range. Here A2 has 3 words, A3 has 3, and A4 has 2, so the total is 8.
| A | B | C | |
|---|---|---|---|
| 1 | Text | ||
| 2 | Excel is fun | 8 | |
| 3 | Learn Excel fast | ||
| 4 | Hello world | ||
| 5 | One | ||
| 6 | Two words | ||
| 7 | Three word phrase | ||
| 8 | Four words in here | ||
| 9 |
=SUMPRODUCT(LEN(TRIM(A2:A4))-LEN(SUBSTITUTE(TRIM(A2:A4)," ",""))+1)3 Handle empty cells
If a cell is empty, the basic formula returns 1 because of the +1. Wrap it in IF to return 0 for empty cells. This example checks A5, which is empty, and returns 0.
| A | B | C | |
|---|---|---|---|
| 1 | Text | ||
| 2 | Excel is fun | 0 | |
| 3 | Learn Excel fast | ||
| 4 | Hello world | ||
| 5 | |||
| 6 | Two words | ||
| 7 | Three word phrase | ||
| 8 | Four words in here | ||
| 9 |
=IF(A5="",0,LEN(TRIM(A5))-LEN(SUBSTITUTE(TRIM(A5)," ",""))+1)Other ways to do it
| Formula | Use it when |
|---|---|
=LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 | Use this basic version when you are sure the cell is not empty. |
=IF(A2="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1) | Use this when some cells may be empty and you want 0 instead of 1. |
=SUMPRODUCT(LEN(TRIM(A2:A10))-LEN(SUBSTITUTE(TRIM(A2:A10)," ",""))+1) | Use this to count words across a whole range at once. |
Practise it
Free exercises with instant feedback. No sign-up needed.
Common mistakes
- The formula returns 1 for an empty cell. Wrap the formula in IF:
=IF(A2="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1). - Extra spaces between words cause an incorrect count. TRIM removes leading, trailing, and multiple spaces, so the formula already handles this. Make sure you use TRIM as shown.
- The formula counts punctuation as part of a word. This is normal; the formula counts words separated by spaces. If you need to ignore punctuation, you would need a more complex formula or a macro.
Questions people also ask
Can I count words in multiple cells at once?
Yes, use =SUMPRODUCT(LEN(TRIM(A2:A10))-LEN(SUBSTITUTE(TRIM(A2:A10)," ",""))+1) to get the total word count for a range.
Does this formula work in Excel for Mac?
Yes, the formula works the same in Excel for Mac and Excel for the web.
How do I count characters instead of words?
Use =LEN(A2) to count characters, or =LEN(TRIM(A2)) to ignore extra spaces.
Functions used
Every formula on this page was checked by SheetSkill’s spreadsheet engine. All how-to guides