SUBSTITUTE removes all spaces from the text, then LEN calculates the length of the text without spaces. This number is then subtracted from the length of the text with spaces, and the number 1 is added to the final result, since the number of words is the number of spaces + 1.
Dealing with extra spaces
What about TRIM, what's it doing in the formula? TRIM removes an extra spaces between words, or at the beginning or end of the text. So, before the length of the text with spaces is calculated, we use TRIM to make sure the text doesn't contain any extra spaces, since extra spaces will throw the word count off.
Dealing with empty cells
The formula in the example shown will return 1 even if a cell is empty. If you need to guard against this problem, using IF and ISBLANK:
The Excel SUBSTITUTE function replaces text in a given string by matching. For example =SUBSTITUTE("952-455-7865","-","") returns "9524557865"; the dash is stripped. SUBSTITUTE is case-sensitive and does not support wildcards.
This video shows you how to use two text functions, CLEAN and TRIM, to strip extra spaces and remove line breaks from text.
Excel Formula Training
Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.