LAMBDA · Text
Last word LAMBDA
xl.last.word returns the text after the last space. Maria Elena Lopez returns Lopez. A single word is returned unchanged.
Syntax =xl.last.word(text)
=LAMBDA(text,
LET(
cleaned, TRIM(text),
IFERROR(TEXTAFTER(cleaned, " ", -1), cleaned)
)
)Arguments
| Name | Required | What to pass |
|---|---|---|
| text | Required | A phrase. The last space is the cut. The marker itself is not included. |
Examples
The family name at the end
=xl.last.word("Maria Elena Lopez")Result Lopez
| A | B | |
|---|---|---|
| 1 | Name | Maria Elena Lopez |
| 2 | Last word | Lopez |
xl.last.word returns Lopez from Maria Elena Lopez. The cut is the last space, so the middle name stays out of the result. A name with no space comes back whole, because TEXTAFTER’s #N/A is replaced with the trimmed text.
This is the family-name guess for “given names, then surname” strings. It is the wrong guess for Lopez, Maria.
Add it to the workbook
Copy the formula in the block above, including the line breaks. Choose Formulas, Name Manager, New. Set the name to xl.last.word, the scope to Workbook, and paste into Refers to. Excel Labs can do the same step: open the Advanced Formula Environment, add that name, and save it back to the workbook. A cell then calls =xl.last.word(...).
The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME? for LAMBDA even when it already has XLOOKUP, FILTER, or LET.
How it works
TRIM collapses extra spaces. TEXTAFTER with instance −1 takes the text after the last space. IFERROR covers the no-space case.
Limits
Hyphens are not spaces. A trailing comma stays attached to the word. TRIM does not remove it.