LAMBDA · Text
Split name LAMBDA
xl.split.name returns the first word and the rest of a personal name. Maria Lopez becomes Maria and Lopez. Maria Elena Lopez keeps Elena with the last name.
Syntax =xl.split.name(name)
=LAMBDA(name,
LET(
clean, TRIM(name),
IF(ISERROR(FIND(" ", clean)),
HSTACK(clean, ""),
HSTACK(TEXTBEFORE(clean, " "), TEXTAFTER(clean, " "))
)
)
)Arguments
| Name | Required | What to pass |
|---|---|---|
| name | Required | A personal name. The first word is the given name. Everything after the first space is the remainder. |
Examples
A two-word name
=xl.split.name("Maria Lopez")Result Maria in the first cell and Lopez in the second.
| A | B | C | |
|---|---|---|---|
| 1 | Full name | Maria Lopez | |
| 2 | Given | Maria | Lopez |
xl.split.name spills two cells. Maria Lopez becomes Maria and Lopez. Maria Elena Lopez becomes Maria and Elena Lopez, because only the first space is the cut. Use that when a middle name should stay with the family name. Use FIRST.WORD and LAST.WORD when you want only the two ends.
TRIM runs first, so a double space or a trailing space does not become an empty word.
Add it to the workbook
Copy the formula in the block above, including the line breaks. Choose Formulas, Name Manager, New. Set the name to xl.split.name, the scope to Workbook, and paste into Refers to. Excel Labs can do the same step: open the Advanced Formula Environment, add that name, and save it back to the workbook. A cell then calls =xl.split.name(...).
The name needs Microsoft 365, Excel 2024, or Excel for the web. Excel 2021 returns #NAME? for LAMBDA even when it already has XLOOKUP, FILTER, or LET.
How it works
FIND tests for a space. A miss is an error, and ISERROR turns that into the one-word result. Otherwise TEXTBEFORE takes the given name and TEXTAFTER takes the rest, including later spaces. HSTACK puts the two pieces side by side.
Limits
Last, First is not reordered. Lopez, Maria comes back as Lopez, and Maria. Swap that with a different rule before you call this. Suffixes such as Jr. stay in the remainder. The function does not know which word is the family name in every culture.