How-to recipes · Text
How to split first and last name in Excel
Split a full name into first and last name with TEXTSPLIT, TEXTBEFORE and TEXTAFTER, LEFT/FIND formulas for older Excel, Flash Fill or Text to Columns.
A list of customers or employees arrives with the full name in one column, but your mail merge, CRM import or sorting needs the first name and the last name in separate columns. Doing it by hand is fine for ten names and impossible for a thousand. Excel offers formulas, a one-shot wizard and a pattern-learning tool. This recipe shows each, and how to deal with the hard cases: middle names, double surnames and extra spaces.
The example data
Four full names in A2:A5, including one with a middle name (Anna Maria Berg) and one with an apostrophe (Liam O'Neil).
Microsoft 365: TEXTSPLIT
TEXTSPLIT cuts a text at every occurrence of a delimiter and spills the pieces into neighbouring cells:
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Full name | |||
| 2 | Maria Lopez | Maria | Lopez | |
| 3 | John Smith | |||
| 4 | Anna Maria Berg | |||
| 5 | Liam O'Neil |
The first name lands in C2 and the last name in D2.
For Anna Maria Berg the same formula returns three pieces, which pushes the surname into a third column. When names have different numbers of words, it is cleaner to take the first word and the last word explicitly with TEXTBEFORE and TEXTAFTER:
- First name:
=TEXTBEFORE(A2," ")returns everything before the first space. - Last name:
=TEXTAFTER(A4," ",-1)returns everything after the last space; the-1counts from the end.
| A | B | C | |
|---|---|---|---|
| 1 | Full name | ||
| 2 | Maria Lopez | ||
| 3 | John Smith | ||
| 4 | Anna Maria Berg | Berg | |
| 5 | Liam O'Neil |
With -1 the middle name is skipped and only the surname is returned.
Result: Berg
Both functions accept a whole range: =TEXTBEFORE(A2:A5," ") spills all four first names at once.
Excel 2016 and 2019: LEFT, RIGHT, MID and FIND
FIND returns the position of the first space; everything before it is the first name:
| A | B | C | |
|---|---|---|---|
| 1 | Full name | ||
| 2 | Maria Lopez | Maria | |
| 3 | John Smith | ||
| 4 | Anna Maria Berg | ||
| 5 | Liam O'Neil |
FIND returns 6, so LEFT takes 5 characters.
Result: Maria
Everything after the first space (the rest of the name) is =MID(A2,FIND(" ",A2)+1,100), using MID with a generous length. For Anna Maria Berg that gives Maria Berg, which is right if Maria is part of the first name and wrong if it is a middle name.
To get only the last word, use this well-known formula, which works in every version:
=TRIM(RIGHT(SUBSTITUTE(A4," ",REPT(" ",100)),100))- SUBSTITUTE replaces every space with 100 spaces, which pushes the words far apart.
- RIGHT takes the last 100 characters, which contain only the last word plus padding.
- TRIM removes the padding, leaving Berg.
No formulas: Flash Fill
- In B2 type the first name of the first row by hand: Maria.
- Press Enter, then press Ctrl+E (Data > Flash Fill) in B3.
- Excel spots the pattern and fills the remaining first names. Repeat in the next column for last names.
Flash Fill (Excel 2013 and later) produces static values. Check the results: with mixed patterns it can guess wrong, and it does not update when the names change.
No formulas: Text to Columns
Select A2:A5, choose Data > Text to Columns, pick Delimited, tick Space, and choose a destination such as C2 so the original column is not overwritten. This is the oldest method and works everywhere; like Flash Fill, the result does not update. More on cleaning text in Text cleanup: TRIM, CLEAN, TEXTSPLIT, Flash Fill and Text to Columns.
Hard cases and pitfalls
- Extra spaces. Two spaces between names create an empty piece. Run TRIM first, or nest it:
=TEXTSPLIT(TRIM(A2)," "). See How to remove spaces in Excel. - "Last, First" format. Split at the comma instead:
=TEXTAFTER(A2,", ")is the first name and=TEXTBEFORE(A2,",")the surname. - Double surnames and particles (van der Berg, de la Cruz) cannot be detected by a formula. The last-word method would return only Berg or Cruz. Review such names manually.
- Single names. If a cell has no space, FIND and TEXTBEFORE return errors. Use the
if_not_foundargument:=TEXTBEFORE(A2," ",,,,A2)returns the whole name. - Titles such as Dr or Mrs become the first name. Remove them first with SUBSTITUTE.