How to count the number of words in a cell
✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)Count how many words are in a text string, ignoring extra spaces.
The formula
| App | Formula | Notes |
|---|---|---|
| Excel (desktop) | =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 | Word count = number of spaces + 1, after trimming. |
| Google Sheets | =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 | Identical. |
| LibreOffice Calc | =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 | Identical. |
How it works
TRIM removes extra spaces. The word count equals the number of single spaces between words plus one. SUBSTITUTE(...," ","") deletes the spaces, and the drop in length tells you how many there were. 'the quick brown fox' has 3 spaces, so 4 words. (An empty cell would wrongly return 1; wrap in IF(A2="",0,...) if that matters.)
Verified, not just documented
We ran =LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1 in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned 4 — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned 4 for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.
Functions used
LEN · TRIM · SUBSTITUTE — see full Excel, Google Sheets & LibreOffice compatibility for each.
Related recipes
- How to count the total words in a range
- How to count items in a comma-separated cell
- How to count occurrences of a substring in a cell
- How to extract the file name from a path or URL
- How to extract the last word from a cell