Spreadsheet Practice

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 to B7
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

  1. A2"Ergonomic office chair"

    The value in A2.

  2. TRIM(A2)"Ergonomic office chair"

    TRIM: Removes extra spaces, leaving single spaces between words.

    • textA2"Ergonomic office chair"
  3. TRIM(A2)=""FALSE

    The = operator tests whether the two sides are equal.

  4. TRIM(A2)"Ergonomic office chair"

    TRIM: Removes extra spaces, leaving single spaces between words.

    • textA2"Ergonomic office chair"
  5. LEN(TRIM(A2))22

    LEN: Number of characters.

    • textTRIM(A2)"Ergonomic office chair"
  6. TRIM(A2)"Ergonomic office chair"

    TRIM: Removes extra spaces, leaving single spaces between words.

    • textA2"Ergonomic office chair"
  7. SUBSTITUTE(TRIM(A2)," ","")"Ergonomicofficechair"

    SUBSTITUTE: Replaces matching text.

    • textTRIM(A2)"Ergonomic office chair"
    • old_text" "
    • new_text""
  8. LEN(SUBSTITUTE(TRIM(A2)," ",""))20

    LEN: Number of characters.

    • textSUBSTITUTE(TRIM(A2)," ","")"Ergonomicofficechair"
  9. LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))2

    The - operator subtracts.

  10. LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+13

    The + operator adds.

  11. IF(TRIM(A2)="",0,LEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+1)3

    IF: Returns one value if a test is true, another if false.

    • logical_testTRIM(A2)=""FALSE
    • value_if_true0not used
    • value_if_falseLEN(TRIM(A2))-LEN(SUBSTITUTE(TRIM(A2)," ",""))+13

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.

FormulaResultWhen 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

In 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.