Sub topic 3
Multiple delimiters, multi-character delimiters, and empty pieces
This chapter covers the third and fourth arguments of SPLIT. I assume you can already write =SPLIT(A2, ",") and know that the pieces spill into the cells to the right. I also assume you know TRIM and that text in a formula goes in double quotes. The chapter explains why SPLIT sometimes cuts text in more places than you intended, and how to control that.
The full signature
SPLIT(text, delimiter, [split_by_each], [remove_empty_text])textis the string to cut.delimiteris the string that marks where to cut.split_by_eachis TRUE by default. It controls whether the delimiter is read as a set of single characters or as one exact sequence.remove_empty_textis TRUE by default. It controls whether empty pieces are dropped.
Both optional arguments are positional. To change remove_empty_text, you must also write a value for split_by_each.
Several delimiters in one call
With the default split_by_each = TRUE, every character in the delimiter string is its own delimiter. This lets one formula handle data that mixes separators.
Suppose A2 contains:
red, green;blue,,yellowThe formula =SPLIT(A2, ",;") cuts at every comma and every semicolon. The result is four cells:
| Cell | Value |
|---|---|
| B2 | `red` |
| C2 | ` green` (with a leading space) |
| D2 | `blue` |
| E2 | `yellow` |
Two things happened here. The space after the first comma stayed, because a space is not in the delimiter string. The empty piece between the two commas after blue was dropped, so yellow moved left.
To remove the stray space, add a space to the delimiter:
=SPLIT(A2, ", ;")This returns red, green, blue, yellow with no spaces. The space joins the delimiter characters, so the empty piece between , and the following space is dropped like any other empty piece.
The order of characters in the delimiter string does not matter. ", ;" and ";, " behave the same.
The cost of treating every character as a delimiter
Adding a space to the delimiter works only when spaces never occur inside a value. Suppose A2 contains:
New York, NY, Los Angeles, CA=SPLIT(A2, ", ") returns New, York, NY, Los, Angeles, CA. That is six pieces where you wanted four. The space inside New York is a delimiter because the delimiter string contains a space.
For this data, the delimiter you mean is the two-character sequence comma-then-space, and you need the next section.
Multi-character delimiters
Set split_by_each to FALSE to make SPLIT treat the delimiter string as one exact sequence:
=SPLIT(A2, ", ", FALSE)On the city data, this returns New York, NY, Los Angeles, CA. A lone comma or a lone space does not trigger a cut. Only the full sequence , does.
This is also the right choice for delimiters that are naturally several characters long. Suppose A2 contains:
Ann Lee | Bob Ray | Cy Fox=SPLIT(A2, " | ", FALSE) returns the three full names. With the default TRUE, the same delimiter would cut at every space and every pipe and give six first and last names.
The same applies to markers like <br>, --, or ::. With TRUE, a marker such as <br> would also cut at every b and r in your data. With FALSE, only the exact sequence cuts.
The following diagram shows how the delimiter string is read.
Choosing between the two modes
Ask whether the delimiter characters can appear on their own inside a value.
| Situation | Setting | Example delimiter | Column |
|---|---|---|---|
| Data mixes several one-character separators | TRUE (default) | `",;"` | |
| Separator is a sequence, and its characters appear alone in values | FALSE | `", "` or `" | "` |
| Separator is a marker like `<br>` | FALSE | `"<br>"` | |
| Single-character separator | Either | `","` |
Empty pieces
An empty piece appears when two delimiters sit next to each other, or when the text starts or ends with a delimiter. By default (remove_empty_text = TRUE) these pieces are dropped, and the remaining pieces shift left to fill the gap.
Take A2 containing a,,b,. The two settings give different results:
| Formula | Result |
|---|---|
| `=SPLIT(A2, ",")` | `a`, `b` |
| `=SPLIT(A2, ",", TRUE, FALSE)` | `a`, (blank), `b`, (blank) |
The default is usually what you want for messy lists, such as one with a doubled comma. Set remove_empty_text to FALSE when position carries meaning. Consider a record like Ann,,Lee, where the middle field is a middle name that happens to be missing. If you drop the empty piece, Lee moves into the middle-name column and your columns no longer line up across rows.
Here is the same data with the empty piece kept, so the columns stay aligned:
=SPLIT(A2, ",", TRUE, FALSE)Row 1 (Ann,Marie,Lee) and row 2 (Ann,,Lee) now both put the last name in the third column.
Leading and trailing spaces are not empty pieces
remove_empty_text removes only pieces with zero characters. A piece that contains a single space is not empty, so it is kept.
Consider A2 containing a, ,b. The formula =SPLIT(A2, ",") returns a, (one space), and b. The middle cell looks blank but holds a space. A formula like =ISBLANK() on it returns FALSE, and it can break lookups later.
The usual fix is to trim every piece after splitting:
=ARRAYFORMULA(TRIM(SPLIT(A2, ",")))TRIM removes leading and trailing spaces and collapses runs of inner spaces into one. A piece of only spaces becomes an empty string. Note that the trimmed piece is now empty but is still in its cell. It is no longer removed, because the removal happens inside SPLIT before TRIM runs.
If you need the empty pieces gone entirely, you must split on the space as well (", " with the default TRUE) or filter the result. If values can contain inner spaces, filter instead:
=FILTER(ARRAYFORMULA(TRIM(SPLIT(A2, ","))), ARRAYFORMULA(TRIM(SPLIT(A2, ","))) <> "")This runs SPLIT twice, but the logic is plain: keep only the trimmed pieces that are not empty. Later chapters build on this idea.
Worked example: a mixed tag column
A2 contains this text, typed by several people:
budget; Q3 ,forecast;; review ,You want clean tags: budget, Q3, forecast, review.
- Split on both separators:
=SPLIT(A2, ",;"). Because the default drops empty pieces, the doubled;;and the trailing comma disappear. The pieces still carry stray spaces:Q3,review. - Wrap the result in
TRIMusingARRAYFORMULA:=ARRAYFORMULA(TRIM(SPLIT(A2, ",;"))).
The final formula returns four cells with clean tags. Because every empty piece was removed before TRIM ran, and none of the remaining pieces was spaces only, no blank cells appear.
Now see what a spaces-only piece does. If A2 were budget; ;forecast, the middle piece is one space. The formula =ARRAYFORMULA(TRIM(SPLIT(A2, ",;"))) returns budget, (blank), forecast. The blank cell comes from the spaces-only piece that TRIM emptied. To avoid it, include the space in the delimiter (", ;") when values never contain inner spaces, or use the FILTER form above.
Blocked spill ranges
SPLIT writes into as many cells to the right as it has pieces. If any of those cells already holds data, the formula returns #REF! and the error message says the array result was not expanded because it would overwrite data. The number of pieces can change when you change remove_empty_text, so a formula that worked with TRUE can fail with FALSE because it now needs more cells. Clear the cells in the way, or move the formula to a row with free space to its right.
Summary of the decisions
- Use the default
split_by_each = TRUEwhen you list several single-character separators in one string. - Use
FALSEwhen the delimiter is a sequence, or when its characters occur by themselves inside your values. - Keep the default
remove_empty_text = TRUEfor messy lists. Use FALSE when columns must line up. - Wrap in
TRIMfor stray spaces, and remember that a spaces-only piece is not empty.
Exercise
Cell A2 contains North America | South America | Asia. You want three cells: North America, South America, Asia. Why does =SPLIT(A2, " | ") give the wrong result, and which formula fixes it?
Show answer
With the default split_by_each = TRUE, the delimiter " | " is read as two separate delimiters, a space and a pipe. The formula therefore also cuts inside North America and South America, producing five pieces: North, America, South, America, Asia. The fix is =SPLIT(A2, " | ", FALSE), which treats " | " as one exact sequence.
Exercise
Cell A2 contains Ann,,Lee. You need Lee to land in the third column, with the second column left blank. Write the formula and explain what the default would have done.
Show answer
=SPLIT(A2, ",", TRUE, FALSE). Setting remove_empty_text to FALSE keeps the empty piece between the two commas, so the result is Ann, (blank), Lee. With the default TRUE, the empty piece is dropped and Lee shifts into the second column.
Exercise
A2 contains x; ;y. The formula =ARRAYFORMULA(TRIM(SPLIT(A2, ",;"))) returns x, a blank cell, and y. Why is there a blank cell, and how can you avoid it?
Show answer
The middle piece is a single space. It is not an empty string, so SPLIT keeps it, and TRIM afterwards turns it into an empty string. Avoid it by adding a space to the delimiter, as in =SPLIT(A2, ",; "), so the space is a delimiter and the resulting empty piece is removed. This is safe only if values never contain inner spaces. Otherwise wrap the trimmed result in FILTER to keep the non-empty pieces.