Text formula page
Extract Last Word Formula
Use this for simple last names, final labels, or last tokens in imported text.
Best for
Extract the last word from a cell.
What it returns
If A2 is Maya Chen, the result is Chen.
Copy formulas
=TEXTAFTER(TRIM(A2), " ", -1)=REGEXEXTRACT(TRIM(A2), "\S+$")Excel uses TEXTAFTER with -1 to search from the last delimiter. Google Sheets uses REGEXEXTRACT for the final non-space run.
Example data
| Raw Text | Example Result |
|---|---|
| Maya Chen | Maya |
| SKU-1001-East | SKU |
| https://www.example.com/pricing | example.com |
| Acme North | Acme North |
What it returns
If A2 is Maya Chen, the result is Chen.
How the formula works
- TRIM normalizes extra spaces.
- Excel searches from the last space.
- Google Sheets captures the final non-space text.
| Syntax piece | Role in the formula |
|---|---|
| TRIM(A2) | The source text with regular leading and trailing spaces removed. |
| " " | The whitespace delimiter used by Excel. |
| -1 | The Excel instance number that selects the last delimiter. |
| \S+$ | The Google Sheets regex for the final non-space run. |
Verified examples
=TEXTAFTER(TRIM(A2), " ", -1)Excel: Enter Maya Chen in A2. Returns: Chen
=REGEXEXTRACT(TRIM(A2), "\S+$")Google Sheets: Enter two leading spaces, Acme, three spaces, North, and two trailing spaces in A2. Returns: North
=REGEXEXTRACT(TRIM(A2), "\S+$")Google Sheets: Enter SKU-1001-East in A2. Returns: SKU-1001-East
Common errors and fixes
| Issue | Likely cause | Fix |
|---|---|---|
| The last word is not found | The text contains nonbreaking spaces that TRIM does not normalize. | Replace imported nonbreaking spaces before extracting the final token. |
| Trailing punctuation remains | The extraction identifies the final token but does not remove punctuation. | Apply punctuation cleanup separately when the output needs plain letters or digits. |
| TEXTAFTER is unavailable | The Excel version does not include the modern TEXTAFTER function. | Use a legacy RIGHT, LEN, and FIND pattern or the split-text alternative. |
When not to use this formula
- Do not use this pattern when a URL host, file extension, or punctuation-delimited field needs URL-aware parsing.
Alternatives
| Alternative | When to use it |
|---|---|
| Split Text Formula | Use when the complete set of tokens should be split into separate cells. |
| Extract First Word Formula | Use when the first token is the required output. |
Related formulas
Official references
- TEXTAFTER function from Microsoft
- REGEXEXTRACT function from Google
FAQ
What does -1 mean in TEXTAFTER?
It tells TEXTAFTER to use the last occurrence of the delimiter rather than the first.
Does the formula remove final punctuation?
No. Punctuation attached to the final token remains in the result.