TEXTSPLIT
Short answer
Split "100-4200-Sales" into its parts
TEXTSPLIT(text, col_delimiter, [row_delimiter], [ignore_empty], [match_mode], [pad_with])
- Category
- Text & Data Cleanup
- Excel version
- 2024+
- Also searched as
- split text, text to columns formula, split by delimiter, split account code into columns, split gl string
What it returns
TEXTSPLIT takes one text string and returns its pieces as a spilled array. Give it a column delimiter and the pieces spill across. Give it a row delimiter and they spill down. Give it both and you get a grid.
=TEXTSPLIT("100-4200-Sales", "-") returns three cells: 100, 4200, Sales. All three are text, including the two that look like numbers.
That last point matters more than the split itself. A segment that reads 4200 will not match the number 4200 in a mapping table, and it will not add up. Convert numeric segments before they go anywhere near a lookup or a sum.
The result is live. Change the source string and the split updates. Text to Columns overwrote the source once and forgot how it did it.
Arguments that matter
| Argument | Required | What it does |
|---|---|---|
text | Yes | The string to split. One cell. See “Where it breaks” for what happens with a range. |
col_delimiter | Yes | What separates columns. A string, or an array constant such as {"-","."} to split on any of several characters. |
row_delimiter | No | What separates rows. Leave col_delimiter empty and set this to split down instead of across. |
ignore_empty | No | FALSE (default) keeps an empty cell for two delimiters in a row. TRUE collapses them. |
match_mode | No | 0 case-sensitive (default). 1 case-insensitive. Only matters for letter delimiters. |
pad_with | No | What fills the gaps when rows split to different lengths. Default is #N/A. |
The array delimiter is the one to learn. Chart-of-accounts strings drift: one entity uses hyphens, an acquired one uses dots. {"-","."} splits both with the same formula.
ignore_empty is a choice about meaning, not tidiness. In 100--Sales, the blank middle segment is information: the account is missing. Leave the default and the gap stays in the account column where a check can find it. Set TRUE and Sales slides left into the account column.
In a financial model
Segmented strings arrive in every ERP extract. Entity, account, department and sometimes project, joined into one field. The reporting model needs them apart, because the statements sum by account and the departmental view sums by department.
TEXTSPLIT is the in-cell way to break that field out. It suits a working tab, a reconciliation, or a quick look at a new extract. For a recurring load, the play on transform in Power Query, not in cells still applies: split the column once at load and keep the model’s formulas for modeling.
Either way the extract itself stays untouched, as in raw data stays raw. The split lives next to it or downstream of it. Nobody pastes over the original.
Once the segments are apart, the rest of the pattern is familiar. XLOOKUP maps the account segment to a statement line. SUMIFS sums by that line.
Worked example
A GL extract on tab GL with a column Segment holding strings like 100-4200-Sales. The parts are entity, natural account, department. You want them in three columns on a working tab, numbers where they should be numbers.
For one string in B5:
=TEXTSPLIT(B5, "-")
Returns 100, 4200, Sales across three cells, all text. To turn the numeric segments into numbers and leave the department as text:
=LET(parts, TEXTSPLIT(B5, "-"), IFERROR(--parts, parts))
The double negative converts 100 and 4200. Sales fails the conversion and IFERROR hands back the text. Fill this down beside the extract, one row per string.
| Segment | Entity | Account | Dept |
|---|---|---|---|
| 100-4200-Sales | 100 | 4200 | Sales |
| 210.6100.Ops | 210 | 6100 | Ops |
| 100-4200 | 100 | 4200 | (blank) |
The second row needs {"-","."} as the delimiter. The third row is a two-segment code from a legacy entity. TEXTSPLIT returns two cells and the Dept cell stays empty, so nothing flags it. Whether that matters depends on whether a missing department is normal or a problem. If it is a problem, add a check column with =COLUMNS(TEXTSPLIT(B5,"-")) and count the rows that return fewer than 3.
Old way vs new way
The middle segment, the old way:
=MID(B5, FIND("-",B5)+1, FIND("-",B5,FIND("-",B5)+1)-FIND("-",B5)-1)
The new way:
=CHOOSECOLS(TEXTSPLIT(B5, "-"), 2)
The old formula counts characters and nests FIND inside FIND. Nobody can audit it at a glance, and a second delimiter type means rewriting it. The new one says what it does: split, take the second piece.
Where it breaks
TEXTSPLIT over a column returns only the first segment of each row. You pointed text at GL[Segment] and got one column of entities, no accounts. TEXTSPLIT cannot return an array of arrays, so given many strings it keeps the first piece of each. Fix: split one cell per row and fill down, or use TEXTBEFORE and TEXTAFTER with an instance number, which do spill cleanly down a column.
Segments match nothing in the mapping table. XLOOKUP returns its not-found flag on every row. The split produced text 4200 and the mapping table holds the number 4200. Fix: convert with -- or VALUE inside the formula, as in the LET above, or store the mapping keys as text consistently.
#SPILL! in a Table column. Tables do not allow spilled results, and TEXTSPLIT always returns more than one cell when the delimiter is found. Fix: put the split on a normal range beside the Table, or extract one segment per Table column with TEXTBEFORE and TEXTAFTER.
#N/A in a split of many strings at once. When you join a column and split it with a row delimiter, rows with fewer segments are padded with #N/A, the pad_with default. Fix: set pad_with to "", or keep the #N/A and use it as a flag if short codes should not exist. A formula filled down one string per row never pads: short codes just spill fewer cells.
Values land in the wrong column. Two delimiters in a row, 100--Sales, combined with ignore_empty set to TRUE. The empty account collapses and Sales moves into the account column. Fix: leave ignore_empty at the default so positions hold.
Stray spaces break the lookup. 100 - 4200 - Sales splits on - and leaves leading and trailing spaces on every piece. Fix: split on " - ", or wrap the result in TRIM.
#NAME? when the file is opened elsewhere. TEXTSPLIT needs Excel 2024 or Microsoft 365. Excel 2021 and earlier show #NAME?. Fix: if the model has to travel, split in Power Query at load instead.
Related functions
- TEXTBEFORE and TEXTAFTER. One segment at a time, by instance number. The better choice when you need a single segment for a whole column, since they spill down without the array-of-arrays limit.
- REGEXEXTRACT. When the parts are defined by a pattern rather than a fixed delimiter, such as a PO number buried in a memo.
- REDUCE. With VSTACK, it can split a whole column into a grid in one formula. Worth it on a working tab. Overkill in a model that already has Power Query.
- XLOOKUP. The next step after the split: account segment to statement line.
- TEXTJOIN. The reverse. Rebuilds a segmented string from its parts.
