Sub topic 11
Split with a formula: the SPLIT function
This chapter assumes you know how to enter formulas, you've used ARRAYFORMULA, and you've seen TRIM and the Split text to columns menu tool from earlier chapters. Here you'll learn how SPLIT works, how its optional arguments behave, and the errors that most often catch people out.
Why use a formula instead of the menu tool
The Split text to columns tool (Data > Split text to columns) writes its results over the cells to the right of your data. It runs once and doesn't update. If the source changes, you split it again by hand.
SPLIT is a formula, so it works differently:
- The original column stays untouched, which fits the "protect the raw data" rule from earlier.
- The result updates whenever the source cell changes.
- You can chain it with TRIM, REGEXREPLACE, and other functions, then fill down the whole column with ARRAYFORMULA.
The trade-off is that the output is formula-driven. If you need static values, copy the result and use Edit > Paste special > Values only.
The syntax
SPLIT(text, delimiter, [split_by_each], [remove_empty_text])| Argument | Meaning | Default |
|---|---|---|
| `text` | The text to divide. Usually a cell reference. | none |
| `delimiter` | The character or characters that mark where to cut. | none |
| `split_by_each` | `TRUE`: every character in `delimiter` is its own separator. `FALSE`: the whole `delimiter` string is one separator. | `TRUE` |
| `remove_empty_text` | `TRUE`: skip empty pieces. `FALSE`: keep them as empty cells. | `TRUE` |
SPLIT puts the first piece in the cell holding the formula and spills the remaining pieces into the cells to its right. You enter the formula once, in one cell.
A basic example
Suppose A2 contains Doe, Jane, a "last, first" name pasted from another system. A comma on its own would leave a leading space on the second piece. This formula treats the comma and space together as one delimiter:
=SPLIT(A2, ", ", FALSE)B2 shows Doe and C2 shows Jane.
Why `split_by_each` matters
The default is TRUE, which treats ", " as two separate delimiters: a comma and a space. For Doe, Jane this gives the same result, because the empty piece between the comma and the space is dropped. The difference appears with other data. Take Van Der Berg, Anna:
- With
TRUE, you getVan,Der,Berg,Anna. The spaces inside the last name also split the value. - With
FALSE, you getVan Der BergandAnna.
Use FALSE whenever your delimiter is a multi-character sequence such as ", ", " - ", or "||". Use TRUE when you want to split on several different single characters at once. For example, SPLIT(A2, ",;") splits on either commas or semicolons.
Choosing arguments
Empty pieces and column alignment
By default SPLIT discards empty pieces. That can shift data left and break column alignment. Consider these three rows, each with the format name,phone,email:
| A |
|---|
| `Ana,555-0101,[email protected]` |
| `Ben,,[email protected]` |
| `Cy,555-0103,[email protected]` |
Row 2 has no phone number. With the default remove_empty_text = TRUE, Ben's email slides into the phone column, and the email column stays empty. Your columns no longer mean what their headers say.
To keep each value in its own column, turn off empty-piece removal. You must supply split_by_each as well, because the arguments are positional:
=SPLIT(A2, ",", TRUE, FALSE)Now Ben's row has an empty phone cell and the email stays in the third column. If you're splitting into fixed fields, you almost always want FALSE here.
Splitting a whole column
SPLIT on a single cell works fine with fill-down. For an entire column, wrap it in ARRAYFORMULA. Combining it with TRIM handles stray spaces around each piece of the original text. This formula, from the cleanup pipeline you'll build later, trims each cell and then splits on commas:
=ARRAYFORMULA(SPLIT(TRIM(A2:A), ","))Two details to note:
- TRIM collapses runs of spaces and removes leading and trailing spaces from the whole cell, but it doesn't touch the spaces next to commas inside the text.
"red , blue"still splits intoredandbluewith spaces attached. To fix this, trim the pieces after splitting:=ARRAYFORMULA(TRIM(SPLIT(A2:A, ","))). Because TRIM accepts an array, this removes the spaces around every piece. - Place the formula in row 2 of an empty area, with the header in row 1. The output needs free cells below and to the right.
Cleaning before you split
If your delimiter doesn't match because the text contains non-breaking spaces (character code 160), SPLIT won't see them as ordinary spaces. Replace them first, using the same technique you saw in the hidden characters chapter:
=ARRAYFORMULA(SPLIT(TRIM(SUBSTITUTE(A2:A, CHAR(160), " ")), " "))For delimiters that vary, normalize them first. If some rows use / and others use -, either use split_by_each = TRUE with both characters, or convert one into the other with SUBSTITUTE before splitting.
Errors and surprises
"Array result was not expanded because it would overwrite data"
SPLIT needs empty cells to spill into. If any cell in the output range already holds a value, the formula shows #REF! and the message appears when you click the cell. Clear the cells in the way, or move the formula to an empty area. This also happens when a later row's split is wider than the space available, so leave generous room on the right.
Numbers and dates get converted
SPLIT converts pieces that look like numbers or dates into real numbers or dates. Splitting 00123;45 gives 123 and 45, so the leading zeros are gone. Splitting 3-4 can turn a piece into a date in some locales. If you need the original text:
- For fixed-width codes such as ZIP codes, pad the result:
=TEXT(B2, "00000"). - For values that must stay text, avoid SPLIT for that field and use REGEXEXTRACT or MID on the original string.
Ragged rows
Rows with fewer pieces than others simply leave blank cells on the right. That is normal, not an error. Rows with more pieces extend the output further right. Check the widest row before you build formulas on top of the output.
Delimiters are case-sensitive
If you split on a word, such as " and ", a row containing " AND " won't split. Normalize case with LOWER first, or use REGEXREPLACE to replace the variants with one delimiter.
Getting one piece or flipping to rows
You don't always need every piece. INDEX picks a single one:
=INDEX(SPLIT(A2, ", ", FALSE), 1, 2)This returns the second piece of the first (and only) row of the result, so Jane for Doe, Jane. A related option is to rotate the output so pieces land in rows instead of columns:
=TRANSPOSE(SPLIT(A2, ","))Use this when a single cell holds a list, such as tags, that you want to count or deduplicate with UNIQUE.
SPLIT versus the menu tool
| Situation | Better choice |
|---|---|
| One-time cleanup of a static export | Split text to columns |
| Source data keeps changing or being re-pasted | SPLIT |
| You must keep the original column unchanged | SPLIT |
| You want to trim, change case, or strip characters in the same step | SPLIT inside a pipeline |
| Output cells to the right contain data you want to keep | SPLIT in a different area, not the menu tool |
Checking your result
After splitting, run a few quick checks:
- Compare the row count of the source and the output. Blanks at the bottom of an ARRAYFORMULA range are normal, but missing rows are not.
- Use
=COUNTA(B2:B)on each output column and compare it to the number of source rows you expect to have a value there. - Scan the widest row. If it has more pieces than you planned, a stray delimiter is hiding in the data.
- Click one or two cells that look like numbers and confirm they weren't converted when they should have stayed text.
Exercise
Cell A2 contains Smith - Jones - Lee and A3 contains Brown - - Park (the middle piece is empty). You want each name in its own column, with the empty one kept as an empty cell so Park stays in the third column. Write one formula for A2 that works when filled down to A3.
Show answer
=SPLIT(A2, " - ", FALSE, FALSE). Setting splitbyeach to FALSE makes " - " a single delimiter, so single spaces or hyphens inside a name don't cut it. Setting removeemptytext to FALSE keeps the empty middle piece, so for A3 you get Brown, an empty cell, and Park in the third column. Note that the empty piece in A3 only appears if the text between the two delimiters is truly empty, which it is when the cell holds Brown - - Park with two spaces between the hyphens, since " - " then matches twice with nothing between.
Exercise
A column of tags such as red, blue,green has inconsistent spacing after the commas. Write one ARRAYFORMULA that splits all rows of A2:A on commas and removes the extra spaces from each piece.
Show answer
=ARRAYFORMULA(TRIM(SPLIT(A2:A, ","))). SPLIT cuts on each comma, and TRIM then removes the leading and trailing spaces on every piece. Trimming before the split with TRIM(A2:A) would not fix the spaces next to the commas.