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.

Beginner TEXTSPLIT TEXTBEFORE TEXTAFTER LEFT RIGHT MID FIND LEN SUBSTITUTE TRIM REPT

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:

C2fx=TEXTSPLIT(A2," ")
ABCD
1Full name
2Maria LopezMariaLopez
3John Smith
4Anna Maria Berg
5Liam 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 -1 counts from the end.
C4fx=TEXTAFTER(A4," ",-1)
ABC
1Full name
2Maria Lopez
3John Smith
4Anna Maria BergBerg
5Liam 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:

C2fx=LEFT(A2,FIND(" ",A2)-1)
ABC
1Full name
2Maria LopezMaria
3John Smith
4Anna Maria Berg
5Liam 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:

Formula
=TRIM(RIGHT(SUBSTITUTE(A4," ",REPT(" ",100)),100))
  1. SUBSTITUTE replaces every space with 100 spaces, which pushes the words far apart.
  2. RIGHT takes the last 100 characters, which contain only the last word plus padding.
  3. TRIM removes the padding, leaving Berg.

No formulas: Flash Fill

  1. In B2 type the first name of the first row by hand: Maria.
  2. Press Enter, then press Ctrl+E (Data > Flash Fill) in B3.
  3. 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_found argument: =TEXTBEFORE(A2," ",,,,A2) returns the whole name.
  • Titles such as Dr or Mrs become the first name. Remove them first with SUBSTITUTE.
Tip. The reverse task, joining names, is in How to combine first and last name in Excel. To capitalise names typed in lower case, see How to capitalize the first letter in Excel.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 16 KB

More how-to recipes