Split Text to Columns Using a Formula in Excel (Dynamic Array)

We can utilize a dynamic array formula to split text into columns instead of using the Text to Columns Wizard in the Data menu in Excel. This helps to keep your delimited strings unaffected.

Excel offers a dedicated function called TEXTSPLIT for splitting text into columns and rows. However, it has a drawback: it cannot be applied to each row in a column without dragging it down.

Of course, you can use the REDUCE function to expand the TEXTSPLIT to each row in the range. But it’s a lambda helper function, and I don’t recommend it for very large datasets.

There is one more workaround. It utilizes the TEXTSPLIT feature for splitting by both row and column delimiters. However, this requires combining all texts in the column and placing a different delimiter to separate each row. This can also cause performance problems.

Instead of resorting to these workarounds, we can adopt a different approach to split text into columns in each row within a range in Excel. This approach involves using the TEXTAFTER and TEXTBEFORE functions.

Sample Data (Text Delimited by Commas)

In one of the Excel spreadsheets, I have the following sample data in cell range A1:A6.

Sample Data Demonstrating Row-Wise Splitting in Excel

When using the dynamic array formula to split text into columns in Excel, it’s crucial to specify the delimiter correctly.

For example, the string in cell A2 is “Apple, Banana, Orange, Grapes”. You can see that the comma is the delimiter. However, it’s important to note that there is a space following each comma. Therefore, the real delimiter is not just a comma, but a comma followed by a space.

Please keep this in mind when using the dynamic array formula to split text into columns in Excel.

Expected Output:

Key Points:

The dynamic array formula converts numeric and date values to numbers, and all remaining values to text.

If you desire, you can make a slight adjustment to the formula to return all values as text. In this case, when utilizing numbers or dates in calculations, it’s recommended to use the VALUE function alongside it.
For example:

=VALUE(E1)

The formula won’t treat consecutive delimiters as one.
For example:

  • “Apple,, Banana, Orange, Grapes” will return “Apple, | Banana | Orange | Grapes”
  • “Apple, , Banana, Orange, Grapes” will return “Apple | | Banana | Orange | Grapes”

If there is a blank row in the range, the formula keeps it.

Split Text to Columns Using a Dynamic Array Formula in Excel

Here is the dynamic array formula to split text into columns in Excel.

=LET(
     r, A1:A6, d, ", ", n, 4, 
     split, 
          TEXTBEFORE(TEXTAFTER(d&r&d, d, SEQUENCE(1, n)), d, 1), 
     IFERROR(IFERROR(split*1, split),"")
)

When you use this formula, replace:

  • A1:A6 (defined as r) with the range to split.
  • ", " (defined as d) with the delimiter to split.
  • 4 (defined as n) with the maximum number of columns you want in the result. In this case, you can use =LET(r, A1:A6, MAX(LEN(r)-LEN(SUBSTITUTE(r, ",", ""))+1)) in any cell and refer to that cell instead of 4. The formula calculates the maximum number of items separated by commas in cells A1 to A6 (the delimiter here is “,” not “, “).

Note: If you do not wish to convert dates and numeric values to numbers, replace IFERROR(IFERROR(split*1, split),"") with IFERROR(split,"").

Splitting Text to Columns Using Dynamic Array Formula with Date Formatting

Formula Explanation: How the Formula Splits Texts in Each Row into Columns

Here are the step-by-step instructions for the dynamic array formula that splits texts into columns in Excel.

Extracting Text After a Given Instance of the Delimiter:

=TEXTAFTER(", "&A1&", ", ", ", SEQUENCE(1, 4))

This formula follows the syntax: TEXTAFTER(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

Where:

  • text: ", "&A1&", " (the delimiter is added on both sides of the text)
  • delimiter: ", "
  • instance_num: SEQUENCE(1, 4) returns the array {1, 2, 3, 4} (it represents the number of columns in the result)

The formula extracts the text after the specific instance of the delimiter. Since the delimiter corresponds to the sequence numbers 1 to 4, it returns the following values:

John, Doe, 30, New York,Doe, 30, New York,30, New York,New York,

Extracting Text Before a Given Instance of the Delimiter:

By wrapping the above formula with TEXTBEFORE, we can extract the text before the first delimiter.

=TEXTBEFORE(TEXTAFTER(", "&A1&", ", ", ", SEQUENCE(1, 4), 1, 1), ", ", 1)

This follows the syntax: TEXTBEFORE(text, delimiter, [instance_num], [match_mode], [match_end], [if_not_found])

Where:

  • text: TEXTAFTER(", "&A1&", ", ", ", SEQUENCE(1, 4), 1, 1)
  • delimiter: ", "
  • instance_num: 1

It extracts the text that occurs before a specific instance of the delimiter. Here it’s 1.

This formula eventually splits the texts in a single row into columns.

JohnDoe30New York

To apply it to each row, replace the cell reference A1 with the range reference A1:A6:

=TEXTBEFORE(TEXTAFTER(", "&A1:A6&", ", ", ", SEQUENCE(1, 4), 1, 1), ", ", 1)
Usage of TEXTBEFORE and TEXTAFTER Functions with Error Handling

Applying LET to Clean the Split Text to Columns Formula:

We then use LET to clean the formula as per the syntax: LET(name1, name_value1, [calculation_or_name2], [name_value2, …])

=LET(
r, A1:A6, d, ", ", n, 4,
TEXTBEFORE(TEXTAFTER(d&r&d, d, SEQUENCE(1, n)), d, 1)
)

We have assigned the name r to A1:A6 (text), d to the delimiter “, ” (delimiter), and n to 4 (instance_num).

Converting Numeric Values and Dates to Numbers in Text Split to Columns:

In our final formula, we named the above formula expression, which is TEXTBEFORE(TEXTAFTER(d&r&d, d, SEQUENCE(1, n)), d, 1), with the name split.

The formula expression in the final formula is:

IFERROR(IFERROR(split*1, split),"")

Where:

  • IFERROR(split*1, split): This part of the formula attempts to convert the text result to numbers. If successful, it returns the result as numbers; otherwise, it returns the original text. This effectively converts numbers and dates formatted as text in the result to numbers while retaining text.
  • The outer IFERROR function removes all other errors in the split text-to-column output.

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Hierarchical Numbering Sequences in Excel

Creating hierarchical numbering sequences in an Excel spreadsheet can significantly improve the way you...

How to Easily Repeat a Sequence of Numbers in Excel

Excel offers multiple ways to accomplish tasks, and the simplicity of each approach depends...

Create a Sequence of Dates at Every Nth Row in Excel (Dynamic Array)

Would you like to create a sequence of dates in every nth row in...

XMATCH Row by Row: Finding Values Across a Range in Google Sheets

Using the BYROW function with XMATCH in Google Sheets allows us to match values...

More like this

Hierarchical Numbering Sequences in Excel

Creating hierarchical numbering sequences in an Excel spreadsheet can significantly improve the way you...

How to Easily Repeat a Sequence of Numbers in Excel

Excel offers multiple ways to accomplish tasks, and the simplicity of each approach depends...

Create a Sequence of Dates at Every Nth Row in Excel (Dynamic Array)

Would you like to create a sequence of dates in every nth row in...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.