Extract the last name
Get the last word of a full name, even when there is a middle name.
The formula
Excel and Google Sheets
=TRIM(RIGHT(SUBSTITUTE(TRIM(A2), " ", REPT(" ", 100)), 100))How it works
SUBSTITUTE(TRIM(A2), " ", REPT(" ", 100))Replaces each space with 100 spaces, pushing the words far apart.
RIGHT(…, 100)Takes the last 100 characters, which contain only the last word plus padding.
TRIM(…)Removes the padding spaces.
Example
| A: Full name | B: Result |
|---|---|
| Maria Lopez | Lopez |
| John Paul Smith | Smith |
| Cher | Cher |
Tips
- In Excel 365: =TEXTAFTER(A2, " ", -1, , , A2) does the same.