Sub topic 4
Splitting a whole column and turning columns into rows
This chapter extends the single-cell SPLIT from earlier chapters to a whole column of text. It also covers TRANSPOSE, which swaps rows and columns. I assume you can enter formulas, you know that SPLIT returns several values that fill neighboring cells, and you know what TRIM does.
Why one formula per row does not scale
=SPLIT(A2, ",") handles one cell. For a column of 500 rows you could copy the formula down 500 times. That works, but it has costs:
- Each row holds its own copy of the formula, so a fix means copying down again.
- Rows added later have no formula until you copy it down.
- Someone can overwrite one formula with a typed value, and nothing warns you.
A better approach is one formula in one cell that produces the whole result block. Google Sheets calls this a spilled result: the formula lives in the top-left cell and its output fills the cells to the right and below.
Splitting a range with ARRAYFORMULA
SPLIT takes one text value. To apply it to every cell in a range, wrap it in ARRAYFORMULA, which tells Sheets to evaluate the inner function once per element of the range.
Suppose A2:A4 contains these values:
| Cell | Value |
|---|---|
| A2 | red,green,blue |
| A3 | one,two |
| A4 | solo |
Put this formula in B2:
=ARRAYFORMULA(SPLIT(A2:A4, ","))The result fills B2:D4:
| Row | B | C | D |
|---|---|---|---|
| 2 | red | green | blue |
| 3 | one | two | (empty) |
| 4 | solo | (empty) | (empty) |
Three things to notice:
- Each input row produces one output row, in the same order. Row 3 of the output belongs to A3.
- The block is as wide as the widest row. A2 has three pieces, so the block has three columns.
- Shorter rows are padded with empty cells. Those cells are blank, not zeros and not errors.
You only type the formula in B2. The cells B3:D4 show the output but contain no formula of their own. If you click C3, the formula bar is empty. The formula that owns them is in B2.
Open-ended ranges and blank rows
Data grows, so you may want a range with no fixed end, such as A2:A. The same formula then covers rows added later:
=ARRAYFORMULA(SPLIT(A2:A, ","))Blank cells in the range produce blank output rows. That is harmless in most sheets, but the spill block reserves cells down to the bottom of the sheet, and anything you later type in that area blocks the spill (see the next section). If you want the output to contain only rows with data, filter the blanks out first:
=ARRAYFORMULA(SPLIT(FILTER(A2:A, A2:A<>""), ","))FILTER keeps the rows where the condition is true, so SPLIT only sees non-empty text. The output is now as tall as the number of filled rows. One caution: if every cell is blank, FILTER returns #N/A because nothing matched. Wrap the formula in IFERROR if that can happen.
When the spill is blocked
A spilled result needs all of its target cells to be empty. If any cell in the output area already holds a value, the formula in the top-left cell shows #REF!. Hovering over it gives a message like "Array result was not expanded because it would overwrite data in C3."
Typical causes:
- You typed a note or leftover value inside the target area.
- An older copy-down formula still sits in some rows of the target area.
- A second spilling formula, placed to the right or below, overlaps the first.
To fix it, clear the cell named in the message, or move the formula to a place with room. Only the named cell has to be cleared. The error disappears and the block fills in as soon as the area is free.
A related habit: put a spilling formula where the area to its right and below is yours alone, and keep headings in the row above, not in the output area.
Cleaning every piece at once
SPLIT does not remove spaces around the pieces. With "red, green, blue", the pieces after the first have a leading space. Because you are already inside ARRAYFORMULA, you can wrap SPLIT in TRIM and clean the whole block in one pass:
=ARRAYFORMULA(TRIM(SPLIT(A2:A4, ",")))The order matters. TRIM works on the pieces, so it goes outside SPLIT. ARRAYFORMULA goes outermost so TRIM is applied to every cell of the block.
Turning the pieces from a row into a column
SPLIT always spreads its pieces across a row. Sometimes you need them down a column, for example when you want a list you can sort, count, or look up against. TRANSPOSE swaps rows and columns, so the first row becomes the first column:
=TRANSPOSE(SPLIT(A2, ","))With A2 holding "red,green,blue", this formula placed in C2 produces:
| Cell | Value |
|---|---|
| C2 | red |
| C3 | green |
| C4 | blue |
The same spill rules apply, now downward: C3 and C4 must be empty.
TRANSPOSE accepts any block, not only a single row. Applying it to the multi-row result from earlier makes each input row a column:
=TRANSPOSE(ARRAYFORMULA(SPLIT(A2:A4, ",")))The output is three rows tall (the widest input had three pieces) and three columns wide (one per input row). Column 1 holds red, green, blue. Column 2 holds one, two, and an empty cell. Column 3 holds solo and two empty cells.
Here is how the shapes change, using a block with R rows and W columns:
| Formula | Output shape |
|---|---|
| `SPLIT(A2, ",")` | 1 row by W columns, where W is the number of pieces |
| `ARRAYFORMULA(SPLIT(A2:A4, ","))` | one row per input cell, W columns for the widest row |
| `TRANSPOSE(SPLIT(A2, ","))` | W rows by 1 column |
| `TRANSPOSE(ARRAYFORMULA(SPLIT(A2:A4, ",")))` | W rows by one column per input cell |
Edge cases to know
- Numbers and dates.
SPLITcan turn pieces that look like numbers or dates into real numbers or dates. A piece such as "007" may appear as 7, and "3/4" may become a date. If leading zeros or exact text matter, check the output. A later chapter showsREGEXEXTRACT, which always returns text. - Trailing delimiters. "a,b," produces pieces "a" and "b". The empty piece after the last comma is dropped by default, because
remove_empty_textisTRUE. Set it toFALSEif you need positions to line up. - Different widths. A block's width comes from the widest row. If one cell holds twenty pieces, every row gets twenty columns, even though most are empty. Check for a rogue row if the output is wider than you expect.
- Cells that are not text.
SPLITworks on the text form of a value. A number such as 1234 becomes the one-piece result "1234". - Recalculation. The block updates when the source range changes. If you need to keep a result as fixed values, copy it and use Paste special, then Values only.
Common mistakes
- Writing
=SPLIT(A2:A10, ",")and expecting one row of results per input. Wrap the call inARRAYFORMULA. - Putting
TRIMinsideSPLIT, as inSPLIT(TRIM(A2:A4), ","). This trims the whole text before splitting, so the spaces after each comma remain. Trim the pieces, not the whole string. - Placing the formula in a cell where something sits to its right or below, then wondering why it shows
#REF!. - Using
A2:Aand leaving other data below the table. The spill area then collides with it.
Exercise
A2:A3 contain "a;b;c" and "d;e". You enter =ARRAYFORMULA(SPLIT(A2:A3, ";")) in B2, and B2 shows #REF! with the message that the array result would overwrite data in C3. What is the cause, what do you do, and what will the final block look like?
Show answer
Cell C3 already contains a value, which blocks the spill. Clear C3 (or move the formula to a free area). The block then fills B2:D3: row 2 holds a, b, c and row 3 holds d, e and an empty cell in D3.
Exercise
A2 holds "x, y, z" (a comma followed by a space). Write one formula that places the pieces down a column with no leading spaces, and say where you put TRIM relative to the other two functions.
Show answer
=TRANSPOSE(ARRAYFORMULA(TRIM(SPLIT(A2, ",")))). TRIM wraps SPLIT so it cleans the pieces, ARRAYFORMULA lets TRIM work on every piece, and TRANSPOSE is outermost to turn the row into a column. Splitting on ", " would also work for this input, but it fails if some rows have no space after the comma.
Exercise
Your formula =ARRAYFORMULA(SPLIT(A2:A, ",")) leaves blank rows reserved down the whole sheet. How can you make the output contain only rows that have data, and what extra problem must you guard against?
Show answer
Filter the blanks out before splitting: =ARRAYFORMULA(SPLIT(FILTER(A2:A, A2:A<>""), ",")). If every cell in A2:A is blank, FILTER returns #N/A, so wrap the whole formula in IFERROR if that can happen.