DataTools AI DataTools AI

How to split first and last names in Google Sheets

You have a column of full names and you need first and last names in separate columns, for a mail merge, a CRM import or just to sort by surname. The examples below assume the full name is in A2.

En español: cómo separar nombre y apellido en Google Sheets.

Step 1: tidy the spaces first

Double spaces and stray spaces at the start or end create empty or shifted columns when you split. Wrap the name in TRIM in every formula below, or clean the column first with Data → Data cleanup → Trim whitespace. If the names were pasted from a website or a PDF, they may contain non-breaking spaces, which TRIM doesn't touch. In that case use TRIM(SUBSTITUTE(A2,CHAR(160)," ")) instead of TRIM(A2). The guide to removing extra spaces covers this in detail.

Step 2: one word per column with SPLIT

=SPLIT(TRIM(A2)," ") puts each word in its own column: "Mary Jane Smith" fills B2, C2 and D2 with Mary, Jane and Smith. It works well when every name has the same number of words. When some people have a middle name and others don't, the last name lands in different columns, so use step 4 instead.

Step 3: without formulas

Select the column and use Data → Split text to columns, then pick Space as the separator. The result overwrites whatever is in the columns to the right, so insert a few empty columns first. It has the same limitation as SPLIT: names with a different number of words won't line up.

Step 4: first name and last name with REGEXEXTRACT

These formulas always take the first word and the last word, no matter how many words are in between:

\S+ means "one or more characters that aren't spaces", ^ is the start of the text and $ the end. If the column contains numbers or other non-text values, use TRIM(A2&"") so REGEXEXTRACT receives text.

If your list is written as "Smith, Mary Jane", split at the comma instead. Last name: =TRIM(REGEXEXTRACT(A2,"^[^,]+")), first name(s): =TRIM(REGEXEXTRACT(A2,",(.*)$")).

Step 5: names with two surnames

In Mexico, Spain and most of Latin America people usually have two surnames, as in "Ana María López García". Taking only the last word would give you "García" and lose "López". To keep both surnames together, take the last two words as the last name and everything before them as the first name(s):

With three or more words this gives "Ana María" and "López García". With only two words, as in "Juan Pérez", it falls back to the first word and the last word. Formulas can't tell "Juan Carlos Pérez" (two first names, one surname) from "Juan Pérez López" (one first name, two surnames), and they will also cut compound surnames such as "de la Cruz". Check those rows by hand (step 7).

Step 6: the whole column with ARRAYFORMULA

Instead of copying the formula down, put one formula in row 2 and let it fill the column. Leave the cells below it empty, or you'll get a #REF! error.

Step 7: check the result

When everything checks out, copy the new columns and paste them back with Edit → Paste special → Values only, so they no longer depend on column A. To fix capitalization as well, see how to fix name capitalization.

Doing this every week? CleanSheet does all of these steps in one click: removes duplicates (even "Juan Perez" vs "juan pérez"), formats phones to E.164, lowercases emails and standardizes dates. Free up to 500 rows. See CleanSheet · Get the $9 template