Text
Trim text to the first N words (or extract the last N words)
Shorten long product titles and descriptions cleanly at word boundaries using TEXTBEFORE(..., " ", N) without slicing words mid-syllable.
Why TEXTBEFORE(..., " ", N) beats fixed LEFT(A2, 40) previews
LEFT(A2, 25) chops words awkwardly in the middle ("Wireless Noise-Cancelli..."). Splitting at the Nth space with TEXTBEFORE(TRIM(A2), " ", N) stops cleanly at a whole-word boundary!
If a short title has FEWER than N words (say 3 words when N = 4), there are only 2 spaces—so TEXTBEFORE(..., " ", 4) throws #N/A! Wrapping IFERROR directly around TEXTBEFORE(..., " ", N) returns the short title untouched without appending an unnecessary ellipsis.
| Full Title (A) | First 4 Words (+ "..." if truncated) | Last 2 Words |
|---|---|---|
| Wireless Noise Cancelling Studio Headphones | Wireless Noise Cancelling Studio... | Studio Headphones |
| USB-C Travel Charger | USB-C Travel Charger (<= 4 words!) | Travel Charger |
Smart N-word preview (adds "..." only when truncated) and last-N-words
Place IFERROR directly around TEXTBEFORE with a sentinel fallback so short strings return cleanly without "...".
=IF(OR(B2<1,B2<>INT(B2)),"Invalid word limit",IF(A2="","",LET(s, TRIM(A2), p, IFERROR(TEXTBEFORE(s, " ", B2), CHAR(1)), IF(p=CHAR(1), s, p & "..."))))Extract the last N words from a cell
Negative instance -2 in TEXTAFTER counts two spaces backward from the end of the string.
=IF(A2="","",LET(s, TRIM(A2), IFERROR(TEXTAFTER(s, " ", -2), s)))Inputs and interpretation
Use a positive integer word limit. Words here are tokens separated by ordinary spaces after TRIM, not linguistic words in every language. Tabs, nonbreaking spaces and punctuation may need preprocessing. The sentinel CHAR(1) must not occur in the text. A word limit does not guarantee a search engine snippet length.
Try the example
Use the original values or change them to test your understanding.