How to extract the last word from a cell
✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)Grab the final word — surnames, trailing codes, last path segments.
The formula
| App | Formula | Notes |
|---|---|---|
| Excel (desktop) | =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100)) | 365: =TEXTAFTER(A2," ",-1) — the -1 means 'after the LAST space'. |
| Google Sheets | =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100)) | Identical; or =INDEX(SPLIT(A2," "),COUNTA(SPLIT(A2," "))). |
| LibreOffice Calc | =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100)) | Identical; TEXTAFTER with -1 works in LibreOffice 25.8+ (#NAME? in 25.2 and older). |
How it works
The mirror of the nth-word trick: pad every space to 100 spaces so each word occupies its own wide slot, take the RIGHTmost 100 characters — which can only contain the final word plus padding — and TRIM it clean: "gamma". Works in every version of everything. On modern versions TEXTAFTER(A2," ",-1) states the intent directly, and swapping the delimiter handles paths ("/") or filenames (".") — that variant is the text-after-last-delimiter recipe.
Verified, not just documented
We ran =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100)) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned gamma — 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 gamma 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
TRIM · RIGHT · SUBSTITUTE · REPT — see full Excel, Google Sheets & LibreOffice compatibility for each.
Related recipes
- How to extract the file name from a path or URL
- How to extract the nth word from a cell
- How to count the total words in a range
- How to count the number of words in a cell
- How to convert a column number to a letter