# How to Split and Index Delimited Text with Excel Formulas

Here's how you can split delimited text into an array with a short Excel formula, and then wrap the formula with the INDEX function to return any value from the array.

5244 For the longest time I’ve wished that Microsoft would add a SPLIT function to Excel. The function would have a syntax like this…

=SPLIT(text, delimiter, [index])

…where text is the text to split, delimiter is the delimiter that separates each chunk of text, and index is the optional number that returns the specified chunk of text.

Maybe someday.

But in the meantime, there are at least two other ways to split text. One of them has been floating around the web for a long time. It’s kind of complex and difficult to explain, but I’ll explain it in detail soon.

The other way works only with versions of Excel that have the FILTERXML function. If you have that function, here’s how to do it…

### Splitting Text with FILTERXML

Suppose that the text A:B:C:D is in cell A1 and you want to split it into four cells of a dynamic array that begins in cell A3. You could do this easily by using FILTERXML.

The first step is to convert the text into XML. This is easy to do with this formula…

A3: =”<p><c>” & SUBSTITUTE(\$A\$1, “:”, “</c><c>” ) & “</c></p>”

…where SUBSTITUTE’s second argument contains the delimiter and where “p” stands for parent and “c” stands for child. The formula returns:

<p><c>A</c><c>B</c><c>C</c><c>D</c></p>

Or, in a structured format, the return value would look like this: This looks very similar to HTML. But XML describes data and HTML describes how data is displayed. And unlike HTML, we can use any tag values we want. So, rather than “p” and “c” I could have used “parent” and “child”…or even “dog” and “cat”.

To filter that XML, we wrap a FILTERXML function around the formula. The function has this syntax:

=FILTERXML( xml, xpath )

And the full formula looks like this:

A3: = FILTERXML( “<p><c>” & SUBSTITUTE( \$A\$1, “:”, “</c><c>” ) & “</c></p>”,
“//c” )

What’s that second XPath argument about? I’ll get to that in a second. But first, let’s complete the formula.

The formula above returns the text in cell A1 split into multiple rows in one column. To return one row of results split into multiple columns, you would wrap TRANSPOSE around it like this:

A3: = TRANSPOSE(
FILTERXML( “<p><c>” & SUBSTITUTE( \$A\$1, “:”, “</c><c>” ) & “</c></p>”,
“//c” )  )

And if you want to return, say, the third value from the array of values, you could, instead, wrap INDEX around the original formula, like this:

A3: = INDEX(
FILTERXML( “<p><c>” & SUBSTITUTE( \$A\$1, “:”, “</c><c>” ) & “</c></p>”,
“//c” ), 3 )

And in all cases, if you copy and paste any of the formulas for cell A3 from this page, you’ll need to delete the carriage return characters before Excel will accept the formulas.

Because I know little about XML, and because Microsoft’s documentation about FILTERXML provides little help about using the XPath argument, I searched for that help online. I found a long page with the title A Really, Really, Really Good Introduction to XML. I also found that W3 Schools has a free tutorial about XML, which includes an extensive XPath Tutorial.

In the W3 tutorial, I learned that the XPath expression “//book” would select all book elements no matter where they are in a document. And sure enough, the XPath “//c” selected all c elements in the formula.

If you’d like to learn more about XML, both the “Really, Really” page and the W3 tutorial would be good places to begin. On the other hand, if you just want to split text by a delimiter, you already have what you need—if your version of Excel has the FILTERXML function.
{"ft_lang_label":"__label__en","ft_lang_prob":0.853644,"math_prob":0.8654669,"size":3441,"snap":"2022-40-2023-06","text_gpt3_token_len":897,"char_repetition_ratio":0.11812627,"word_repetition_ratio":0.038333334,"special_character_ratio":0.26997966,"punctuation_ratio":0.12691772,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95106876,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-09-25T00:59:15Z\",\"WARC-Record-ID\":\"<urn:uuid:8e4dd973-89a1-407a-8118-bb59d06e4216>\",\"Content-Length\":\"384717\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:41cf67aa-ab37-44bd-b2b7-971f3cde451b>\",\"WARC-Concurrent-To\":\"<urn:uuid:38bf8ac4-b467-4371-acdb-f0731a8b2dbd>\",\"WARC-IP-Address\":\"70.32.23.71\",\"WARC-Target-URI\":\"https://exceluser.com/6705/how-to-split-and-index-delimited-text-with-excel-formulas/\",\"WARC-Payload-Digest\":\"sha1:47AP5VRTLDPYZ26IT6IDS4IFLTAEDQL5\",\"WARC-Block-Digest\":\"sha1:YWTMRTFIC2ZBJHCE7NGRJHLQC42KOYOA\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030334332.96_warc_CC-MAIN-20220925004536-20220925034536-00663.warc.gz\"}"}