fxExcelReps

← How-to guides

How to Extract the Last Name in Excel

The last name is the text after the last space. In Microsoft 365: =TEXTAFTER(A2, " ", -1), where -1 means the last space. In older Excel, a classic trick replaces the last space with a marker and takes everything after it.

{"cells": {"A1": "Full name", "A2": "Anna Petrova", "A3": "Ivan Georgiev", "A4": "Maria Ivanova Dimitrova", "A5": "Elena Stoyanova", "B1": "Last name", "B2": "=TEXTAFTER(A2,\" \",-1)", "B3": "=TEXTAFTER(A3,\" \",-1)", "B4": "=TEXTAFTER(A4,\" \",-1)", "B5": "=TEXTAFTER(A5,\" \",-1)", "C1": "Older Excel", "C2": "=TRIM(RIGHT(SUBSTITUTE(A2,\" \",REPT(\" \",100)),100))", "C3": "=TRIM(RIGHT(SUBSTITUTE(A3,\" \",REPT(\" \",100)),100))", "C4": "=TRIM(RIGHT(SUBSTITUTE(A4,\" \",REPT(\" \",100)),100))", "C5": "=TRIM(RIGHT(SUBSTITUTE(A5,\" \",REPT(\" \",100)),100))"}, "focus": "B4", "note": "Row 4 has a middle name: both formulas still return the last word."}

TEXTAFTER (Microsoft 365)

The -1 counts from the end, so it works with middle names too.

=TEXTAFTER(A2, " ", -1)Petrova from "Anna Petrova", Dimitrova from "Maria Ivanova Dimitrova".

Older Excel: SUBSTITUTE and RIGHT

Replace every space with 100 spaces, take the last 100 characters, and TRIM the padding away.

=TRIM(RIGHT(SUBSTITUTE(A2, " ", REPT(" ", 100)), 100))The last word in any version.

Only two names

When every name has exactly one space, RIGHT with LEN and FIND is enough.

=RIGHT(A2, LEN(A2)-FIND(" ", A2))Everything after the first space.

Common mistakes

Middle names end up in the result
RIGHT(A2, LEN(A2)-FIND(" ", A2)) uses the first space. Use one of the last-space formulas.
Trailing spaces
A space at the end of the cell makes the last word empty. Use TRIM(A2) inside the formula.

Frequently asked questions

How do I get the first name?

See extract the first name.

How do I split a full name into two columns?

Data → Text to Columns → Delimited → Space, or in Microsoft 365 =TEXTSPLIT(A2, " "). See split text by a delimiter.

Does this work for "Surname, First" names?

Then the surname is before the comma: =TEXTBEFORE(A2, ",").

Practise it

RIGHTLENSUBSTITUTETEXTBEFORE, TEXTAFTER

Think you know this?

15 formula tasks, no hints, with a leaderboard. Absolute, relative and mixed references included.

Take the Pro Challenge →

More how-to guides

How to Combine First and Last Name in Excel

Join first and last names in Excel with &, CONCAT or TEXTJOIN, with a space, a comma, or initials, and skip empty cells.

How to Split Text by a Delimiter in Excel

Split text at a comma, dash or space in Excel with TEXTBEFORE and TEXTAFTER, LEFT, MID and FIND, or Text to Columns.

How to Sum by Month in Excel

Total amounts by month in Excel from a list of dates, with SUMIFS and EOMONTH or SUMPRODUCT with MONTH. Live example included.

How to Calculate Age in Excel

Calculate age from a date of birth in Excel with DATEDIF, in years or in years and months, and why subtracting years gives wrong ages.