Excel guide · 5 min read
How to switch "Last, First" to "First Last" in Excel
=TRIM(TEXTAFTER(A2,","))&" "&TRIM(TEXTBEFORE(A2,",")). TEXTAFTER takes everything after the comma (the first name), TEXTBEFORE takes everything before it (the last name), and TRIM removes the space after the comma. In Excel 2021 and older, use =TRIM(MID(A2,FIND(",",A2)+1,LEN(A2)))&" "&TRIM(LEFT(A2,FIND(",",A2)-1)).Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | |
|---|---|
| 1 | Client (Last, First) |
| 2 | Garcia, Maria |
| 3 | O'Brien,Sean |
| 4 | Nguyen, Thi Lan |
| 5 | Smith Jr., Robert |
| 6 | de la Cruz , Ana |
| 7 | Chen Wei |
| 8 | MCDONALD, KAREN |
| 9 | Okafor, Chidi E. |
Download this sheet as an Excel practice file (.xlsx)
The quick version: TEXTAFTER and TEXTBEFORE
Column A is a client list exported from a CRM, where every name came out as "Last, First". Mail merges, name badges and email greetings all need "First Last".
The comma is the key. Split on the comma, not on a space, and surnames like "de la Cruz" and first names like "Thi Lan" stay in one piece. Splitting on spaces would break both.
TEXTAFTER and TEXTBEFORE are in Excel for Microsoft 365, Excel for the web and Excel 2024. Put the formula in B2 and double-click the fill handle to copy it down the list.
Result: Maria Garcia
Maria Garcia. TEXTAFTER returns Maria, TEXTBEFORE returns Garcia, and &" "& puts a space between them.
Why ", " breaks on some rows (and the fix)
The formula above searches for a comma followed by a space. Row 3 was typed as "O'Brien,Sean" with no space, so ", " is never found and TEXTAFTER returns #N/A. Real exports always have a few rows like this.
The safer pattern searches for the comma alone and lets TRIM clean up whatever spacing is around it. TRIM removes leading and trailing spaces and squeezes runs of spaces down to one, so it also fixes rows like A6, which has spaces before the comma and after the name.
Result: Sean O'Brien
Sean O'Brien, even though there was no space after the comma.
Messy spacing and multi-word names
A6 is " de la Cruz , Ana " with spaces all over the place. Because the split happens at the comma, the three-word surname survives intact, and TRIM strips the padding on both sides.
The same formula gives Thi Lan Nguyen for A4, Robert Smith Jr. for A5 and Chidi E. Okafor for A9. A suffix like Jr. sits before the comma, so it stays attached to the surname, which is where people expect to see it.
Result: Ana de la Cruz
Ana de la Cruz.
Names with no comma
A7 is "Chen Wei" with no comma. It may already be in the right order, or it may be a family-name-first name that should not be flipped at all. Either way, a formula cannot know, so the sensible rule is to leave it alone. Without a fix, TEXTAFTER returns #N/A and the MID/FIND version returns #VALUE!.
TEXTBEFORE and TEXTAFTER have a sixth argument, if_not_found. Give TEXTAFTER an empty string and TEXTBEFORE the original cell, and rows without a comma come back unchanged. The outer TRIM removes the extra space that is left at the front. Wrapping the earlier formula in IFERROR(...,TRIM(A2)) does the same job and is easier to read, but it also hides any other error.
Result: Chen Wei
Chen Wei, returned as it was instead of #N/A. On "Garcia, Maria" the same formula still returns Maria Garcia.
Excel 2021 and older: MID, FIND and LEFT
Without TEXTAFTER, find the comma's position with FIND and cut around it. LEFT(A4,FIND(",",A4)-1) takes everything up to the comma. MID(A4,FIND(",",A4)+1,LEN(A4)) takes everything after it; using LEN(A4) as the length is a simple way to say "to the end".
For rows without a comma, wrap it in a test: =IF(ISNUMBER(FIND(",",A2)), formula above, TRIM(A2)). This works in every version of Excel, including Excel 2010.
Result: Thi Lan Nguyen
Thi Lan Nguyen.
ALL CAPS exports: add PROPER, then check the result
Some systems export names in capitals. Wrap the whole formula in PROPER to capitalise the first letter of each word. PROPER also capitalises after an apostrophe, so O'BRIEN becomes O'Brien.
PROPER does not know names, though. MCDONALD becomes Mcdonald, DE LA CRUZ becomes De La Cruz and VAN DER BERG becomes Van Der Berg. Only use PROPER when the source really is all capitals, and scan the result for Mc, Mac and particles like de, van and von before you send anything addressed to real people.
Result: Karen Mcdonald
Karen Mcdonald. The spelling is right but the capital D is lost, so fix names like this by hand.
No formulas: Flash Fill
For a one-off clean-up, Flash Fill is fastest. It works in Excel 2013 and later. It copies the pattern you type, so give it a clean example and then check the rows that look different.
- In B2, type the first name the way you want it: Maria Garcia.
- Select B3 and press Ctrl+E (or Data > Flash Fill).
- Check the odd rows: no-comma names, suffixes and multi-word surnames are where Flash Fill guesses wrong.
Which method to use
Use the TRIM(TEXTAFTER) formula in Excel 365 when the list will be refreshed, because it updates when the source changes. Use the MID/FIND version if anyone opening the file has Excel 2021 or older, since TEXTAFTER shows #NAME? there. Use Flash Fill for a one-time job, then delete column A.
If you need to replace the original column, copy the results and use Home > Paste > Paste Values over column A. Deleting column A while the formulas still point at it turns every result into #REF!.
Common mistakes
Searching for ", " (comma and space)
Rows typed without the space return #N/A. Search for "," alone and wrap each part in TRIM.
Splitting on the space instead of the comma
"de la Cruz, Ana" or "Nguyen, Thi Lan" then splits in the wrong place. The comma is the only reliable boundary in a "Last, First" list.
Deleting the original column
The formulas depend on it and turn into #REF!. Paste the results as values first (Home > Paste > Paste Values), then delete.
Trusting PROPER on every name
PROPER turns McDonald into Mcdonald and de la Cruz into De La Cruz. Only use it on ALL CAPS sources and check the output.
FAQ
How do I reverse last name and first name in Excel?
If names are written "Last, First", use =TRIM(TEXTAFTER(A2,","))&" "&TRIM(TEXTBEFORE(A2,",")) in Excel 365, or =TRIM(MID(A2,FIND(",",A2)+1,LEN(A2)))&" "&TRIM(LEFT(A2,FIND(",",A2)-1)) in older versions. Fill it down, then paste as values if you want to replace the originals.
How do I flip "First Last" to "Last, First"?
Split on the last space instead of a comma. In Excel 365, =TEXTAFTER(A2," ",-1)&", "&TEXTBEFORE(A2," ",-1) uses -1 to mean the last space, so "Mary Ann Lee" becomes "Lee, Mary Ann". Double surnames without a comma cannot be detected by any formula, so check those by hand.
Why does my formula show #NAME?
TEXTAFTER and TEXTBEFORE only exist in Excel for Microsoft 365, Excel for the web and Excel 2024. In Excel 2021, 2019 or older, use the MID, FIND and LEFT version, which works everywhere.
Can I flip names without a formula?
Yes. Type the first result in the next column and press Ctrl+E for Flash Fill. It is quick, but it does not update when names change and it can guess wrong on unusual rows, so check it.
What about names with a middle name or suffix?
Because the formula splits at the comma, "Okafor, Chidi E." becomes "Chidi E. Okafor" and "Smith Jr., Robert" becomes "Robert Smith Jr.". Everything before the comma stays together and everything after it stays together.
Functions used
TEXTAFTERText after a delimiterTEXTBEFOREText before a delimiterTRIMRemoves extra spacesMIDCharacters from the middleFINDPosition of text (case-sensitive)LEFTCharacters from the startLENLength of textPROPERCapitalize Each WordIFERRORFallback when a formula errorsISNUMBERIs it a number?
Related guides
- How to separate first and last name in Excel
- How to combine first and last name in Excel
- How to extract text after a character in Excel
- How to extract text before a character in Excel
- How to extract the domain from an email address in Excel
- How to find the nth occurrence of a character in Excel
Updated