Day(s)

:

Hour(s)

:

Minute(s)

:

Second(s)

8 Ways to Split Text by Delimiter in Excel

When data is imported into Excel it can be in many formats depending on the source application that has provided it.

For example, it could contain names and addresses of customers or employees, but this all ends up as a continuous text string in one column of the worksheet, instead of being separated out into individual columns e.g. name, street, city.

You can split the data by using a common delimiter character. A delimiter character is usually a comma, tab, space, or semi-colon. This character separates each chunk of data within the text string.

A big advantage of using a delimiter character is that it does not rely on fixed widths within the text. The delimiter indicates exactly where to split the text.

You may need to split the data because you may want to sort the data using a certain part of the address or to be able to filter on a particular component. If the data is used in a pivot table, you may need to have the name and address as different fields within it.

This article shows you eight ways to split the text into the component parts required by using a delimiter character to indicate the split points.

Sample Data

The above sample data will be used in all the following examples. Download the example file to get the sample data plus the various solutions for extracting data based on delimiters.

Excel Functions to Split Text

There are several Excel functions that can be used to split and manipulate text within a cell.

LEFT Function

The LEFT function returns the number of characters from the left of the text.

Syntax

= LEFT ( Text, [Number] )
  • Text – This is the text string that you wish to extract from. It can also be a valid cell reference within a workbook.
  • Number [Optional] – This is the number of characters that you wish to extract from the text string. The value must be greater than or equal to zero. If the value is greater than the length of the text string, then all characters will be returned. If the value is omitted, then the value is assumed to be one.

RIGHT Function

The RIGHT function returns the number of characters from the right of the text.

Syntax

= RIGHT ( Text, [Number] )

The parameters work in the same way as for the LEFT function described above.

FIND Function

The FIND function returns the position of specified text within a text string. This can be used for locating a delimiter character. Note that the search is case-sensitive.

Syntax

= FIND (SubText, Text, [Start])
  • SubText – This is a text string that you want to search for.
  • Text – This is the text string which is to be searched.
  • Start [Optional] – The starting position for the search.

LEN Function

The LEN function will give the length by number of characters of a text string.

Syntax

= LEN ( Text )
  • Text – This is the text string of which you want to determine the character count.

Extracting Data with the LEFT, RIGHT, FIND and LEN Functions

Using the first row (B3) of the sample data, these functions can be combined to split a text string into sections using a delimiter character.

= FIND ( ",", B3 )

You use the FIND function to get the position of the first delimiter character. This will return the value 18.

= LEFT ( B3, FIND( ",", B3 ) - 1 )

You can then use the LEFT function to extract the first component of the text string.

Note that FIND gets the position of the first delimiter, but you need to subtract 1 from it so as to not include the delimiter character.

This will return Tabbie O’Hallagan.

= RIGHT ( B3, LEN ( B3 ) - FIND ( ",", B3 ) )

It is more complicated to get the next components of the text string. You need to remove the first component from the text by using the above formula.

This formula takes the length of the original text, finds the first delimiter position, which then calculates how many characters are left in the text string after that delimiter.

The RIGHT function then truncates off all the characters up to and including that first delimiter so that the text string gets shorter and shorter as each delimiter character is found.

This will return 056 Dennis Park, Greda, Croatia, 44273

You can now use FIND to locate the next delimiter and the LEFT function to extract the next component, using the same methodology as above.

Repeat for all delimiters, and this will split the text string into component parts.

FILTERXML Function as a Dynamic Array

If you’re using Excel for Microsoft 365, then you can use the FILTERXML function to split text with output as a dynamic array.

You can split a text string by turning it into an XML string by changing the delimiter characters to XML tags. This way you can use the FILTERXML function to extract data.

XML tags are user defined, but in this example, s will represent a sub-node and t will represent the main node.

= "<t><s>" & SUBSTITUTE ( B2, ",", "</s><s>" ) & "</s></t>"

Use the above formula to insert the XML tags into your text string.

<t><s>Name</s><s>Street</s><s>City</s><s>Country</s><s>Post Code</s></t>

This will return the above formula in the example.

Note that each of the nodes defined is followed by a closing node with a backslash. These XML tags define the start and finish of each section of the text, and effectively act in the same way as delimiters.

=TRANSPOSE(
    FILTERXML(
        "<t><s>" &
        SUBSTITUTE(
            B3,
            ",",
            "</s><s>"
        ) & "</s></t>",
        "//s"
    )
)

The above formula will insert the XML tags into the original string and then use these to split out the items into an array.

As seen above, the array will spill each item into a separate cell. Using the TRANSPOSE function causes the array to spill horizontally instead of vertically.

FILTERXML Function to Split Text

If your version of Excel doesn’t have dynamic arrays, then you can still use the FILTERXML function to extract individual items.

= FILTERXML (
    "<t><s>" &
    SUBSTITUTE (
        B3,
        ",",
        "</s><s>"
    ) & "</s></t>",
    "//s"
)

You can now break the string into sections using the above FILTERXML formula.

This will return the first section Tabbie O’Hallagan.

= FILTERXML (
    "<t><s>" &
    SUBSTITUTE (
        B3,
        ",",
        "</s><s>"
    ) & "</s></t>",
    "//s[2]"
)

To return the next section, use the above formula.

This will return the second section of the text string 056 Dennis Park.

You can use this same pattern to return any part of the sample text, just change the [2] found in the formula accordingly.

Flash Fill to Split Text

Flash Fill allows you to put in an example of how you want your data split.

You can check out this guide on using flash fill to clean your data for more details.

You then select the first cell of where you want your data to split and click on Flash Fill. Excel will populate the remaining rows from your example.

Using the sample data, enter Name into cell C2, then Tabbie O’Hallagan into cell C3.

Flash fill should automatically fill in the remaining data names from the sample data. If it doesn’t, you can select cell C4, and click on the Flash Fill icon in the Data Tools group of the Data tab of the Excel ribbon.

Similarly, you can add Street into cell D2, City into cell E2, Country into cell F2, and Post Code into cell G2.

Select the subsequent cells (D2 to G2) individually, and click on the Flash Fill icon. The rest of the text components will be populated into these columns.

Text to Columns Command to Split Text

This Excel functionality can be used to split text in a cell into sections based on a delimiter character.

  1. Select the entire sample data range (B2:B12).
  2. Click on the Data tab in the Excel ribbon.
  3. Click on the Text to Columns icon in the Data Tools group of the Excel ribbon and a wizard will appear to help you set up how the text will be split.
  4. Select Delimited on the option buttons.
  5. Press the Next button.
  1. Select Comma as the delimiter, and uncheck any other delimiters.
  2. Press the Next button.
  3. The Data Preview window will display how your data will be split. Choose a location to place the output.
  4. Click on Finish button.

Your data will now be displayed in columns on your worksheet.

Convert the Data into a CSV File

This will only work with commas as delimiters, since a CSV (comma separated value) file depends on commas to separate the values.

Open Notepad and copy and paste the sample data into it. You can open Notepad by typing Notepad into the search box at the left of the Windows task bar or locate it in the application list.

Once you have copied the data into Notepad, save it off by using File ➜ Save As from the menu. Enter a filename with a .csv suffix e.g. Split Data.csv.

You can then open this file in Excel. Select the csv file in the browser file type drop down and click OK. Your data will automatically appear with each component in separate columns.

VBA to Split Text

VBA is the programming language that sits behind Excel and allows you to write your own code to manipulate data, or to even create your own functions.

To access the Visual Basic Editor (VBE), you use Alt + F11.

Sub SplitText()

Dim MyArray() As String, Count As Long, i As Variant

For n = 2 To 12
	MyArray = Split(Cells(n, 2), ",")
	Count = 3
	For Each i In MyArray
		Cells(n, Count) = i
		Count = Count + 1
	Next i
Next n

End Sub

Click on Insert in the menu bar, and click on Module. A new pane will appear for the module. Paste in the above code.

This code creates a single dimensional array called MyArray. It then iterates through the sample data (rows 2 to 12) and uses the VBA Split function to populate MyArray.

The split function uses a comma delimiter, so that each section of the text becomes an element of the array.

A counter variable is set to 3 which represents column C, which will be the first column for the split data to be displayed.

The code then iterates through each element in the array and populates each cell with the element. Cell references are based on n for the row, and Count for the column.

The variable Count is incremented in each loop so that the data fills across the row, and then downwards.

Power Query to Split Text

Power Query in Excel allows a column to be manipulated into sections using a delimiter character.

Related posts:

The first thing to do is to define your data source, which is the sample data that you entered into you Excel worksheet.

Click on the Data tab in the Excel ribbon, and then click on Get Data in the Get & Transform Data group of the ribbon.

Click on From File in the first drop down, and then click on From Workbook in the second drop down.

This will display a file browser. Locate your sample data file (the file that you have open) and click on OK.

A navigation pop-up will be displayed showing all the worksheets within your workbook. Click on the worksheet which has the sample data and this will show a preview of the data.

Expand the tree of data in the left-hand pane to show the preview of the existing data.

Click on Transform Data and this will display the Power Query Editor.

Make sure that the single column with the data in it is highlighted. Click on the Split Column icon in the Transform group of the ribbon. Click on By Delimiter in the drop down that appears.

This will display a pop-up window which allows you to select your delimiter. The default is a comma.

Click OK and the data will be transformed into separate columns.

Click on Close and Load in the Close group of the ribbon, and a new worksheet will be added to your workbook with a table of the data in the new format.

Power Pivot Calculated Column to Split Text

You can use Power Pivot to split the text by using calculated columns.

Click on the Power Pivot tab in the Excel ribbon and then click on the Add to Data Model icon in the Tables group.

Your data will be automatically detected and a pop-up will show the location. If this is not the correct location, then it can be re-set here.

Leave the My table has headers check box un-ticked in the pop-up, as we want to split the header as well.

Click on OK and a preview screen will be displayed.

Right-click on the header for your data column (Column1) and click on Insert Column in the pop-up menu. This will insert a calculated column where a formula can be entered.

= LEFT ( [Column1], FIND ( ",", [Column1] ) - 1 )

In the formula bar, insert the above formula.

This works in a similar way to the functions described in method 1 of this article.

This formula will provide the Name component within the text string.

Insert another calculated column using the same methodology as the first calculated column.

= LEFT (
    RIGHT ( [Column1], LEN ( [column1] ) - LEN ( [Calculated Column 1] ) - 1 ),
    FIND (
        ",",
        RIGHT ( [Column1], LEN ( [column1] ) - LEN ( [Calculated Column 1] ) - 1 )
    ) - 1
)

Insert the above formula into the formula bar.

This is a complicated formula, and you may wish to break it into sections using several calculated columns.

This will provide the Street component in the text string.

You can continue modifying the formula to create calculated columns for all the other components of the text string.

The problem with a pivot table is that it needs a numeric value as well as text values. As the sample data is text only, a numeric value needs to be added.

Click on the first cell in the Add Column column and enter the formula =1 in the formula bar.

This will add the value of 1 all the way down that column. Click on the Pivot Table icon in the Home tab of the ribbon.

Click on Pivot Table in the pop-up menu. Specify the location of your pivot table in the first pop-up window and click OK. If the Pivot Table Fields pane does not automatically display, right click on the pivot table skeleton and select Show Field List.
Click on the Calculated Columns in the Field List and place these in the Rows window.

our pivot table will now show the individual components of the text string.

Conclusions

Dealing with comma or other delimiter separated data can be a big pain if you don’t know how to extract each item into its own cell.

Thankfully, Excel has quite a few options that will help with this common task.

Which one do you prefer to use?

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Subscribe

Subscribe for awesome Microsoft Excel videos 😃

John MacDougall

I’m John, and my goal is to help you Excel!

You’ll find a ton of awesome tips, tricks, tutorials, and templates here to help you save time and effort in your work.

Related Posts

Comments

9 Comments

  1. John

    Hi Richard – wow, this is a comprehensive list! I generally use LEFT or MID, or in some cases text to columns. I had not considered some of these other methods—great list!

  2. mARK rYAN

    FilterXML by dynamic array is a bit of a game changer for something I’ve been working on for a while – it would be a lifesaver if it could be applied to another dynamic array as opposed to a single cell – That way the output dynamic array wuld grow and shrink with the number of records in the delimited data set. Any suggestions from the author or the brain trust that end up on this page?

    • John

      That is an array of an array situation which unfortunately isn’t supported at the moment.

  3. Sunil

    It is an excellent learning.

    • John

      Thanks!

  4. David

    Hi Richard, great work. Here’s a 9th way as FILTERXML is not available on the browser version of Excel. So for a comma separated string in cell c9:

    =TRIM(MID(C9,TRANSPOSE(FIND(CHAR(160),SUBSTITUTE(CONCATENATE(“,”,C9),”,”,CHAR(160),SEQUENCE(LEN(C9)-LEN(SUBSTITUTE(C9,”,”,””))+1)))),TRANSPOSE(FIND(CHAR(160),SUBSTITUTE(CONCATENATE(C9,”,”),”,”,CHAR(160),SEQUENCE(LEN(C9)-LEN(SUBSTITUTE(C9,”,”,””))+1)))) – TRANSPOSE(FIND(CHAR(160),SUBSTITUTE(CONCATENATE(“,”,C9),”,”,CHAR(160),SEQUENCE(LEN(C9)-LEN(SUBSTITUTE(C9,”,”,””))+1))))))

    • John

      Wow, it’s a long one. Perfect use for the new LAMBDA and LET functions.

  5. JP Mouton

    Hi Richard,

    Thank you!

    Needed to do a text-to-columns now for a string – the =Left(Find) formula is a perfect fit!

    Kind regards,

    • John MacDougall

      Glad to hear it worked for you!

Get the Latest Microsoft Excel Tips

Follow Us

Follow us to stay up to date with the latest in Microsoft Excel!

Subscribe for awesome Microsoft Excel videos 😃