Cellwise Start free

Excel guide · 5 min read

How to split text by a delimiter in Excel

Quick answerIn Excel 365 or 2024, =TEXTSPLIT(A2,",") splits A2 at every comma and spills the pieces into the cells to the right; wrap it in TRIM to remove the spaces after each comma. For a one-off split that does not need to update, select the column and use Data > Text to Columns > Delimited.

Sample data

Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.

AB
1Contact (Name, City, Country)SKU
2Lena Fischer, Berlin, GermanyTSH-BLK-M
3Omar Haddad, Lyon, FranceTSH-WHT-L
4Kim Tran,Hanoi,VietnamHD-GRY-XL
5Raj Patel, PuneCAP-NVY
6Sofia Russo, Milan, ItalyTSH-RED-S

Download this sheet as an Excel practice file (.xlsx)

Method 1: TEXTSPLIT (Excel 365 and 2024)

This contact export crams name, city and country into one column. TEXTSPLIT takes the text and the delimiter and returns one piece per column. Split A2 at "," and you get Lena Fischer, " Berlin" and " Germany", each with the space that followed the comma. Wrap the whole thing in TRIM, which trims every piece of the result, and the spaces are gone.

Why not split on ", " (comma and space) instead? Because exports are rarely consistent. Row 4 has no spaces after its commas, so ", " finds nothing there and returns the whole text in one cell. Splitting on the comma alone and trimming handles both, and also the double space in row 6. For a dash, use =TEXTSPLIT(B2,"-"), which turns TSH-BLK-M into TSH, BLK and M.

=TRIM(TEXTSPLIT(A2,","))

Result: spills 1 row × 3 columns

Lena FischerBerlinGermany

Lena Fischer | Berlin | Germany, spilled into three cells with no leading spaces.

Split a whole column, and the #N/A padding

Fill =TRIM(TEXTSPLIT(A2,",")) down the column and each row spills its own pieces to the right. That is the simplest setup. A single TEXTSPLIT pointed at A2:A6 does not give you one row per contact, because a spilled formula cannot return a separate list for each cell.

If you want one formula for the whole table, join the rows first with a row delimiter and split on both: TEXTJOIN puts a ";" between the contacts, then TEXTSPLIT splits columns at "," and rows at ";". Raj Patel has no country, so his row is one piece short. TEXTSPLIT fills the gap with #N/A unless you give it the last argument, pad_with. Here it pads with an empty text "". TEXTJOIN returns #VALUE! if the joined text passes 32,767 characters, so keep this for lists of moderate size.

=TRIM(TEXTSPLIT(TEXTJOIN(";",TRUE,A2:A6),",",";",FALSE,0,""))

Result: spills 5 rows × 3 columns

Lena FischerBerlinGermany
Omar HaddadLyonFrance
Kim TranHanoiVietnam
Raj PatelPune
Sofia RussoMilanItaly

A 5-row, 3-column table. Raj Patel's country cell is empty instead of #N/A.

Method 2: TEXTBEFORE and TEXTAFTER for one piece

Often you need only one part, such as the city, in its own column. TEXTAFTER(A2,",") returns everything after the first comma, and TEXTBEFORE then cuts that at the next comma, leaving the middle part. TEXTAFTER(A2,",",-1) gives the last part: a negative instance counts from the end.

Watch the rows with fewer parts. For Raj Patel, "Pune" has no comma after it, so a plain TEXTBEFORE returns #N/A. Its fifth argument, match_end, set to 1 treats the end of the text as a delimiter, so the formula below returns Pune for Raj and Berlin for Lena. These functions also need Excel 365 or 2024.

=TRIM(TEXTBEFORE(TEXTAFTER(A5,","),",",1,0,1))

Result: Pune

Pune: the city for Raj Patel, even though his entry has no second comma.

Method 3: MID, SUBSTITUTE and REPT (any Excel version)

Older Excel has no TEXTSPLIT. The first part is easy: =LEFT(A2,FIND(",",A2)-1) returns Lena Fischer. The middle part with FIND needs the position of the second comma and gets long fast. A shorter trick works for any position: replace every comma with 100 spaces, cut out the n-th 100-character block with MID, and TRIM the padding away.

For the 2nd piece, MID starts at character 101; for the 3rd, at 201, and so on. If a piece is missing, as Raj's country is, the result is an empty text instead of an error. Use a width larger than your longest piece; 100 suits names, cities and codes.

=TRIM(MID(SUBSTITUTE(A6,",",REPT(" ",100)),101,100))

Result: Milan

Milan: the 2nd piece of Sofia Russo's entry, with the double space cleaned up.

Method 4: Text to Columns (no formulas)

When you just need the data split once, Text to Columns is fastest and works in every version. It overwrites the original column and the columns to its right, and the result does not update if the source changes. Make sure the columns to the right are empty, or work on a copy.

Tick "Treat consecutive delimiters as one" when values are separated by several spaces. TEXTSPLIT has the same option as its fourth argument, ignore_empty: =TEXTSPLIT(A2," ",,TRUE) skips the empty piece between two spaces.

  1. Select A2:A6 (one column only).
  2. Go to Data > Text to Columns, choose Delimited and click Next.
  3. Tick Comma (or Space, or tick Other and type a dash). Check the preview, then click Next.
  4. Pick a column in the preview and set it to Text if it holds IDs or codes with leading zeros, so Excel does not turn 00742 into 742.
  5. Set Destination to an empty cell such as C2 to keep the original column, then click Finish.

Common mistakes

Splitting on ", " when some rows use "," without a space

Rows without the space stay in one piece. Split on the comma alone and wrap the result in TRIM.

#SPILL! after filling TEXTSPLIT down

Each row spills to the right, so the cells next to it must be empty. Clear them, or move the formula to a column with free space on its right.

#N/A in the last columns of some rows

Those rows have fewer parts. Add pad_with as TEXTSPLIT's sixth argument, for example "" or "-", or use match_end in TEXTBEFORE.

Text to Columns overwrote the data next to it

Press Ctrl+Z straight away. Next time set the Destination to an empty column in the last step.

FAQ

How do I split text into columns in Excel?

Select the column and use Data > Text to Columns > Delimited, then choose your delimiter. With a formula in Excel 365 or 2024, =TEXTSPLIT(A2,",") spills each part into its own column and updates when A2 changes.

How do I split text by more than one delimiter?

Give TEXTSPLIT an array of delimiters, for example =TEXTSPLIT(A2,{"-","/"}) to split at dashes and slashes. In Text to Columns, tick more than one box, or tick Other for a character that is not listed.

How do I split text into rows instead of columns?

Use the row delimiter, TEXTSPLIT's third argument, and leave the column delimiter empty: =TEXTSPLIT(A2,,",") lists each part down a column.

How do I split text in Excel 2016 or 2019 without TEXTSPLIT?

Use =TRIM(MID(SUBSTITUTE(A2,",",REPT(" ",100)),(n-1)*100+1,100)), replacing n with the position of the part you want. Or use Text to Columns or Flash Fill (Ctrl+E) if the result does not need to update.

Why does TEXTSPLIT show #NAME?

Your version of Excel does not have TEXTSPLIT. It is in Excel for Microsoft 365, Excel for the web and Excel 2024. Use the MID and SUBSTITUTE formula or Text to Columns instead.

Functions used

Related guides

Updated