How to count words in a cell in Excel
Formula (Excel and Google Sheets)
=IF(TRIM(A2)="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1)Count the spaces in the trimmed text and add one: =IF(TRIM(A2)="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1).
- Result on the example
- one result per row in
B2, filled down toB7 - Works in
- Excel 2024 and Microsoft 365
- Google Sheets
- Same formula
See it work
The formula is already in B2, filled down to B7. Change any input and the result updates, or edit the formula to experiment.
How it works
TRIM leaves exactly one space between words, so the number of words is the number of spaces plus one. LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ","")) counts the spaces: the length drops by one for each space removed. The IF returns 0 for an empty cell, which would otherwise count as one word.
=IF(TRIM(A2)="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1)Result3
A2"Ergonomic office chair"The value in A2.
TRIM(A2)"Ergonomic office chair"TRIM: Removes extra spaces, leaving single spaces between words.- text
A2"Ergonomic office chair"
- text
TRIM(A2)=""FALSEThe = operator tests whether the two sides are equal.
TRIM(A2)"Ergonomic office chair"TRIM: Removes extra spaces, leaving single spaces between words.- text
A2"Ergonomic office chair"
- text
LEN(TRIM(A2))22LEN: Number of characters.- text
TRIM(A2)"Ergonomic office chair"
- text
TRIM(A2)"Ergonomic office chair"TRIM: Removes extra spaces, leaving single spaces between words.- text
A2"Ergonomic office chair"
- text
SUBSTITUTE(TRIM(A2)," ","")"Ergonomicofficechair"SUBSTITUTE: Replaces matching text.- text
TRIM(A2)"Ergonomic office chair" - old_text
" " - new_text
""
- text
LEN(SUBSTITUTE(TRIM(A2)," ",""))20LEN: Number of characters.- text
SUBSTITUTE(TRIM(A2)," ","")"Ergonomicofficechair"
- text
LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))2The - operator subtracts.
LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+13The + operator adds.
IF(TRIM(A2)="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1)3IF: Returns one value if a test is true, another if false.- logical_test
TRIM(A2)=""FALSE - value_if_true
0not used - value_if_false
LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+13
- logical_test
In Google Sheets
The same formula works in Google Sheets: =IF(TRIM(A2)="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1). We ran it in Google Sheets mode on the same data and it returns the same results.
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =IF(TRIM(A2)="",0,COUNTA(TEXTSPLIT(TRIM(A2)," "))) | 3, 3, 1… | Excel 365: split into words and count them. |
Common mistakes
- Without TRIM, extra spaces count as extra words: " Adjustable standing desk " would give 9.
- Hyphenated words count as one, and words separated only by a line break are counted as one. Replace CHAR(10) with a space first if your text has line breaks.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Count words in a cell
B2, count the words in the text (0 for an empty cell) and fill down to B7.Questions
How do I count the words in a whole range?
Sum the per-cell counts: =SUMPRODUCT(LEN(TRIM(A2:A7))-LEN(SUBSTITUTE(TRIM(A2:A7)," ",""))+(TRIM(A2:A7)<>"")).
How do I count how often one word appears?
Remove it and divide by its length: =(LEN(A2)-LEN(SUBSTITUTE(LOWER(A2),"late","")))/LEN("late").
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.