The TEXTSPLIT function
TEXTSPLIT breaks a piece of text apart at every marker and spills the pieces into neighbouring cells, so one formula fills several columns.
Give it a column marker to split across, a row marker to split down, or both to build a small table from one cell.
=TEXTSPLIT(text, col_delimiter, [row_delimiter], [ignore_empty], [match_mode], [pad_with])
Arguments
- text
- The text (or cell) to split.
- col_delimiter
- The marker that starts a new column, such as
",". Leave it empty if you only split into rows. - row_delimiteroptional
- The marker that starts a new row, such as
";". - ignore_emptyoptional
- TRUE to drop empty pieces, such as those from two commas in a row. The default is FALSE.
- match_modeoptional
- 0 for case-sensitive matching (the default), 1 to ignore case.
- pad_withoptional
- What to fill short rows with when splitting into a grid. Without it they show #N/A.
Try it
=TEXTSPLIT(A2,",") in B2. The three pieces spill into B2, C2 and D2: Halifax, HX1 2AB and West Yorkshire.
B2
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Imported line | |||
| 2 | Halifax,HX1 2AB,West Yorkshire | Halifax | HX1 2AB | West Yorkshire |
| 3 | ||||
| 4 | Leeds,LS1;York,YO1;Hull,HU1 | |||
| 5 | ||||
| 6 | Tea,,Coffee,Juice | |||
| 7 | ||||
| 8 |
Edit the formula in B2, or change the data, and press Enter.
More examples
| Formula | Result | What it does |
|---|---|---|
| =COLUMNS(TEXTSPLIT(A2,",")) | 3 | Two commas, so three pieces. |
| =INDEX(TEXTSPLIT(A2,","),1,2) | HX1 2AB | INDEX picks one piece out of the split, here the second. |
| =INDEX(TEXTSPLIT(A4,",",";"),3,1) | Hull | Semicolons start new rows and commas new columns, so row 3, column 1 is Hull. |
| =COLUMNS(TEXTSPLIT(A6,",",,TRUE)) | 3 | With ignore_empty TRUE, the empty piece between the two commas is dropped. |
Tips
- Keep the cells to the right (or below) empty. TEXTSPLIT needs room to spill.
- Split on several markers at once with curly brackets:
TEXTSPLIT(A2,{",",";"}). - Pieces come back as text, even digits. Wrap the result in VALUE if you need numbers.
Common mistakes
- You get #SPILL!.Something is in the way of the results. Clear the cells to the right of (or below) the formula.
- Pieces start with a space after splitting at commas.Include the space in the marker (
", "), or wrap the result in TRIM. - Splitting into a grid shows #N/A in some cells.Rows have different numbers of pieces. Set pad_with, e.g.
TEXTSPLIT(A4,",",";",,,"").
In Google Sheets
Google Sheets uses SPLIT instead: =SPLIT(A2, ","). By default SPLIT treats each character of the marker as a separate marker and drops empty pieces; set its third argument to FALSE to split on a whole multi-character marker such as ", ". SPLIT only splits across columns, and it turns pieces that look like numbers into numbers.
Practise TEXTSPLIT with instant feedback
Type real formulas into a working spreadsheet and get told straight away whether they work.