Skip to content

How to reverse first and last names in Excel in Excel

Turn "Last, First" into "First Last" and back again with TEXTBEFORE and TEXTAFTER, or with MID and FIND in any version.

A system exports names as "Nair, Priya" and your mail merge wants "Priya Nair". Or the other way round: you have "Priya Nair" and a sorted list needs "Nair, Priya".

Both directions work the same way: cut the name at the separator, then join the two pieces in the opposite order.

For "Last, First", the separator is a comma and a space:

=TEXTAFTER(A2, ", ") & " " & TEXTBEFORE(A2, ", ")

TEXTAFTER returns what follows the separator, which is the first name. TEXTBEFORE returns what precedes it, the last name. The ampersand joins them with a space between.

For "First Last", cut at the space and put a comma between: =TEXTAFTER(C2, " ") & ", " & TEXTBEFORE(C2, " ").

In versions before Microsoft 365, use MID, LEFT and FIND. FIND returns the position of the comma, and the pieces are cut from there: =MID(A2, FIND(", ", A2)+2, 100) & " " & LEFT(A2, FIND(",", A2)-1).

Watch for names that do not follow the pattern. A name with no comma returns #N/A from TEXTAFTER and TEXTBEFORE, which you can catch with IFERROR and return the original name. Names with suffixes such as Jr., or with several words in the surname, will split at the first separator and may need a manual check.

If you only need to do this once, Flash Fill can learn it: type the first result by hand beside the data, then choose Data > Flash Fill or press Ctrl+E. It writes fixed text. The Logic and text track practises splitting and joining.

3 ways to do it

1TEXTAFTER and TEXTBEFORE

=TEXTAFTER(A2,", ")&" "&TEXTBEFORE(A2,", ")

  1. In B2 type =TEXTAFTER(A2,", ")&" "&TEXTBEFORE(A2,", ") to turn "Nair, Priya" into "Priya Nair".
  2. For the opposite direction use =TEXTAFTER(C2," ")&", "&TEXTBEFORE(C2," ").

2MID, LEFT and FIND (any version)

=MID(A2,FIND(", ",A2)+2,100)&" "&LEFT(A2,FIND(",",A2)-1)

  1. FIND returns the position of the comma.
  2. MID returns the text after it, LEFT returns the text before it, and & joins them with a space.

3Flash Fill (fixed text)

  1. Type the first reversed name by hand beside the data.
  2. Choose Data > Flash Fill or press Ctrl+E to fill the rest.

Try it yourself

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B2, turn the name in A2 from Last, First into First Last. Fill down to B8.

Answer in B2, then it fills down to B8.

B2
A
B
C
D
E
1
Last, First
First Last
First Last
Last, First
2
Nair, Priya
Joel Hansen
3
Becker, Tom
Mia Torres
4
Ortiz, Lena
Ravi Menon
5
Webb, Marcus
Ella Brandt
6
Tan, Aiko
Kofi Mensah
7
Okafor, Sam
Anya Petrov
8
Kapoor, Rhea
Luca Romano

Learn it properly, one graded sheet at a time.

Logic and text covers this in lesson 11, MID and FIND.