在 Excel 與 Google Sheets 中把全名拆成名、中間名和姓

兩個詞的姓名先取第一個詞和最後一個詞。Google Sheets 中用 TRIM 後的 LEFT/FIND 與“最後一個詞”公式,Ada Lovelace 得到 Ada 與 Lovelace。本次測試裡 TEXTBEFORE、TEXTAFTER、TEXTSPLIT 返回 #NAME?,不要假設它們在所有表格中可用。

本文目錄

快速解答

兩個詞的姓名先取第一個詞和最後一個詞。Google Sheets 中用 TRIM 後的 LEFT/FIND 與“最後一個詞”公式,Ada Lovelace 得到 Ada 與 Lovelace。本次測試裡 TEXTBEFORE、TEXTAFTER、TEXTSPLIT 返回 #NAME?,不要假設它們在所有表格中可用。

=IFERROR(LEFT(TRIM(A2), FIND(" ", TRIM(A2))-1), TRIM(A2))
=TRIM(RIGHT(SUBSTITUTE(TRIM(A2), " ", REPT(" ", 100)), 100))

檢查重點

逗號格式 Smith, John 不能按空格拆,否則逗號會留在姓上。先判斷是否有逗號,再分別取逗號前後的文本;本次測試得到 John / Smith,以及 CHEN, Wei-Ming 的 Wei-Ming / CHEN。中間名可用正則取出首尾詞之間的部分,Mary Ann Evans 得到 Ann。

邊界與相容性

稱謂和字尾無法靠一個公式可靠處理。Dr. Jane A. Smith Jr. 的首尾詞是 Dr. 與 Jr.。de la 這類介詞、連字元名字和隱藏空格也需要額外規則。SPLIT 或 TEXTSPLIT 需要右側空列,否則會因無法展開而出現 #REF!。請保留原始全名列以便核對。

完整英文範例、公式與作者備註

Tested in: Live formulas in Google Sheets on November 12, 2026, using the name list below. Excel 365 function behavior is taken from Microsoft’s TEXTBEFORE, TEXTAFTER and TEXTSPLIT documentation and was not re-tested in a desktop Excel workbook on this date.

Which versions this applies to

  • Google Sheets: LEFT/FIND, the last-word SUBSTITUTE trick, SPLIT, and REGEXEXTRACT all worked in this test. TEXTBEFORE, TEXTAFTER and TEXTSPLIT returned #NAME?. If your domain already offers those three names in autocomplete, you can use the Excel formulas as written; do not assume they exist until you check.
  • Excel for Microsoft 365, Excel 2021 and Excel 2024: Microsoft documents TEXTBEFORE, TEXTAFTER and TEXTSPLIT. The older LEFT/FIND and last-word formulas also work.
  • Excel 2019 and earlier: There is no TEXTBEFORE / TEXTSPLIT. Use the LEFT/FIND and last-word formulas, or Data > Text to Columns.

The sample names

Full nameFirst wordLast wordNotes
Ada LovelaceAdaLovelaceThe clean two-word case
Mary Ann EvansMaryEvansMiddle name is Ann
Jean-Luc PicardJean-LucPicardThe hyphen stays in the first name
Dr. Jane A. Smith Jr.Dr.Jr.A first/last-word split is the wrong answer
Li WeiLiWeiTwo-word name, no comma
Smith, JohnJohnSmithComma style: family name first
MadonnaMadonnaMadonnaNo delimiter; first and last are the same cell
José GarcíaJoséGarcíaAccented letters came through unchanged
Ada Lovelace AdaLovelaceAfter TRIM; raw length was 18, trimmed length 12
Anna-Maria de la CruzAnna-MariaCruzde la is not a middle name in the usual sense
CHEN, Wei-MingWei-MingCHENComma style, hyphenated given name
Billy-Bob ThorntonBilly-BobThorntonHyphenated given name, two tokens

First name and last name in Google Sheets

TRIM the cell first. Extra spaces turned Ada Lovelace (LEN 18) into Ada Lovelace (LEN 12), after which the same formulas as the clean row worked.

First word, with a fallback so a single name such as Madonna does not become #VALUE!:

=IFERROR(LEFT(TRIM(A2), FIND(" ", TRIM(A2))-1), TRIM(A2))

Last word, by padding spaces and taking the rightmost 100 characters, then trimming:

=TRIM(RIGHT(SUBSTITUTE(TRIM(A2), " ", REPT(" ", 100)), 100))

On Madonna, FIND there is no space, so the first-name formula returned Madonna and the last-word formula also returned Madonna. On Ada Lovelace, they returned Ada and Lovelace. On Mary Ann Evans they returned Mary and Evans, which is usually what you want if the middle name belongs in its own column.

REGEXEXTRACT produced the same first and last tokens in this test:

=IFERROR(REGEXEXTRACT(TRIM(A2), "^(\S+)"), "")
=IFERROR(REGEXEXTRACT(TRIM(A2), "(\S+)$"), "")

Jean-Luc and Billy-Bob stayed as one token, because a hyphen is not whitespace. That is typically what you want.

Middle name (or everything between the first and last word)

This Sheets formula returned Ann for Mary Ann Evans, Jane A. Smith for Dr. Jane A. Smith Jr., de la for Anna-Maria de la Cruz, and a blank for two-word names:

=IFERROR(TRIM(REGEXEXTRACT(TRIM(A2), "^\S+\s+(.+)\s+\S+")), "")

A blank middle name is the correct result for Ada Lovelace. It is not a reliable “middle name” field for the doctor/Jr. row or for particles such as de la, van or von. If you need those handled, you need a rule list or a manual pass, not a longer regex.

Comma-style names: Smith, John

A space split is the wrong tool here. SPLIT on Smith, John produced Smith, and John — the comma stuck to the family name. These two formulas treat a comma as “family name first, given name after” and otherwise fall back to first word / last word:

=IF(A2="", "", IF(ISNUMBER(FIND(",", A2)),
    TRIM(MID(A2, FIND(",", A2)+1, 99)),
    IFERROR(LEFT(TRIM(A2), FIND(" ", TRIM(A2))-1), TRIM(A2))))
=IF(A2="", "", IF(ISNUMBER(FIND(",", A2)),
    TRIM(LEFT(A2, FIND(",", A2)-1)),
    TRIM(RIGHT(SUBSTITUTE(TRIM(A2), " ", REPT(" ", 100)), 100))))

In this test they returned John / Smith for Smith, John and Wei-Ming / CHEN for CHEN, Wei-Ming. Rows without a comma, including Ada Lovelace and José García, still used the first-word / last-word path.

If a list mixes both styles, run this pair rather than a single FIND-on-space formula down the column.

Splitting every word into its own column

Google Sheets’ SPLIT function spilled tokens into neighboring cells. For Mary Ann Evans the three cells were Mary, Ann, Evans. For Dr. Jane A. Smith Jr. they were Dr., Jane, A., Smith, Jr.

=SPLIT(TRIM(A2), " ", TRUE, TRUE)

The last two arguments drop extra delimiters, which is why the padded Ada Lovelace row still spilled as two cells, Ada and Lovelace. Leave empty columns to the right. If the next column already has a formula, Sheets returns #REF! (array result was not expanded) instead of the split values — the same class of collision described in Fix “Array Result Was Not Expanded Because It Would Overwrite Data”.

You can also use Data > Split text to columns on a selected range when this is a one-off cleanup rather than a formula you want to keep.

Excel 365: TEXTBEFORE, TEXTAFTER and TEXTSPLIT

Microsoft documents these three functions for Excel for Microsoft 365 (and they are the cleanest way to write the same logic there). They were not available in the Google Sheets file tested on November 12, 2026 (#NAME? on each).

First word and last word:

=IFERROR(TEXTBEFORE(TRIM(A2), " "), TRIM(A2))
=IFERROR(TEXTAFTER(TRIM(A2), " ", -1), TRIM(A2))

The -1 as instance_num means “the last delimiter,” so Mary Ann Evans should return Evans rather than Ann Evans. TEXTSPLIT puts each word in its own cell, like Sheets’ SPLIT:

=TEXTSPLIT(TRIM(A2), " ")

Comma-style in Excel 365 can use the same IF/FIND wrapper, with TEXTBEFORE / TEXTAFTER in place of LEFT / MID:

=IF(ISNUMBER(FIND(",", A2)), TRIM(TEXTAFTER(A2, ",")), IFERROR(TEXTBEFORE(TRIM(A2), " "), TRIM(A2)))
=IF(ISNUMBER(FIND(",", A2)), TRIM(TEXTBEFORE(A2, ",")), IFERROR(TEXTAFTER(TRIM(A2), " ", -1), TRIM(A2)))

Because those Excel formulas were not entered in a desktop workbook this date, treat them as documented usage, then confirm once in your own file. The LEFT/FIND and last-word formulas above are the ones that were actually checked, and they work in both apps.

What a formula cannot sort out for you

These are name-list problems, not formula bugs:

  • Titles and suffixes. Dr. Jane A. Smith Jr. will not become Jane / Smith unless you first strip a known list of titles (Dr., Mr., Ms., Prof.) and suffixes (Jr., Sr., III). A first/last-word split of that row was Dr. and Jr.
  • Particles and multi-word family names. Anna-Maria de la Cruz gave first word Anna-Maria, last word Cruz, and “middle” de la. Whether the family name should be de la Cruz is a convention, not something FIND can decide.
  • Hyphens vs spaces. Jean-Luc and Billy-Bob stayed together, which is usually right. A last name written with a hyphen also stays together.
  • Mixed punctuation. If some rows use commas and others do not, detect the comma first, as in the pair of formulas above.
  • Hidden characters. If FIND cannot see a space you can see, check for non-breaking spaces the way the TRIM not working article describes, then TRIM again.

Keep the original full-name column. Split results are easy to correct when the source is still there.

Excel vs. Google Sheets

TaskGoogle Sheets (tested 12 Nov 2026)Excel 365 (from Microsoft’s docs)Older Excel
First / last wordLEFT/FIND and the SUBSTITUTE last-word formula; or REGEXEXTRACTTEXTBEFORE / TEXTAFTER with instance_num -1, or the same older formulasLEFT/FIND and the last-word formula
Every word in its own columnSPLIT(TRIM(A2), " ", TRUE, TRUE)TEXTSPLITText to Columns
Comma-style Smith, JohnFIND the comma, then LEFT / MIDTEXTBEFORE / TEXTAFTER on the comma, or the same LEFT / MIDLEFT / MID
TEXTBEFORE / TEXTSPLIT#NAME? in this test fileDocumented as availableNot available

Common mistakes

  1. Taking everything after the first space as the last name. For Mary Ann Evans that returns Ann Evans, not Evans. Use the last-word formula or TEXTAFTER with -1.
  2. Running a space split on Smith, John. You will keep the comma and reverse the fields. Detect the comma first.
  3. Filling an entire column from one happy example. Ada Lovelace is the easy case. The Dr./Jr. row is the one that shows whether the method is good enough for your list.
  4. Putting SPLIT or TEXTSPLIT next to other formulas. The spill needs empty cells. This test produced #REF! when SPLIT collided with a neighboring formula column.
  5. Skipping TRIM. Leading spaces and doubled inner spaces change FIND positions and inflate LEN. The padded Ada row was 18 characters before TRIM and 12 after.

FAQ

How do I split first and last name in Google Sheets?

Use the LEFT/FIND formula for the first word and the SUBSTITUTE last-word formula for the last word, after TRIM. REGEXEXTRACT with ^(\S+) and (\S+)$ matched the same tokens in this test. Do not assume TEXTBEFORE exists; it returned #NAME? here.

How do I get the last word, not everything after the first space?

=TRIM(RIGHT(SUBSTITUTE(TRIM(A2), " ", REPT(" ", 100)), 100)) returned Evans for Mary Ann Evans, Cruz for Anna-Maria de la Cruz, and Lovelace for Ada Lovelace.

What about names written as Last, First?

If the cell contains a comma, take the text after it as the given name and the text before it as the family name. In this test, Smith, John became John / Smith and CHEN, Wei-Ming became Wei-Ming / CHEN.

Why did Madonna not return an error?

The first-name formula uses IFERROR, so a cell with no space returns the whole trimmed name. The last-word formula also returns that single word. That is the useful behavior for mononyms.

Will this work for Dr. Jane A. Smith Jr.?

Not as a first-and-last-name split. First word was Dr. and last word was Jr. Strip titles and suffixes first, or correct those rows by hand.

Live-test findings

All Sheets results above come from one file dated November 12, 2026. TEXTBEFORE, TEXTAFTER and TEXTSPLIT returned #NAME?. LEFT/FIND, the last-word SUBSTITUTE formula, REGEXEXTRACT, SPLIT, and the comma-aware pair were checked against the twelve sample names, including a padded Ada Lovelace row (LEN 18 before TRIM, 12 after) and accented letters in José García.

Sources

Oscar

專注電子表格公式與排錯;具體測試環境和待驗證事項見各篇文章。

Tested in Google Sheets, November 12, 2026. Excel TEXTBEFORE, TEXTAFTER and TEXTSPLIT notes follow Microsoft documentation and were not re-tested in a desktop Excel workbook on this date..

本主題下一篇:資料清理與錄入 FIND 與 SEARCH:Excel 和 Google Sheets 該用哪一個