Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split a string (cell) in Excel without VBA (e.g. for array formula)

Tags:

excel

I have data in an Excel spreadsheet with delimited strings. For simplicity, think of something like "4#8#10", with an arbitrary number of pieces.

Is there any way to split this into an array for use with an array formula? For example, something like SUM(SplitStr(A1,"#")). (This does not work - it just returns "4".)

Is there a good way of approaching this? My ideal solution would end up with an array, as if the user entered {4,8,10} for use in array formulas.

The application of my sheet does not allow for delimiter-based text to columns and summing that. I would prefer to not use VBA if possible as I will not be the primary consumer of the sheet.

Thanks, Terry

like image 641
terry87 Avatar asked Aug 14 '14 19:08

terry87


People also ask

How do I split a string into an array in Excel?

Excel does not provide a dedicated function to split a text string to an array, like PHP's explode(), or Python's split(). However, you can use the LAMBDA function to create a custom function that works in a similar way. Custom LAMBDA functions do not require VBA, but are only available in Excel 365.

How do you split a string and put it in an array?

The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.

How do you break an array formula in Excel?

The result will look like a bunch of error values and/or incorrect results. That's OK. Then, select the new first cell of the array formula, SHIFT+click the new last cell with the array formula, click in the formula bar and use CTRL+SHIFT+ENTER. Delete the cells that are no longer part of the array formula.


1 Answers

Use XML functionality:

={SUM(FILTERXML("<t><s>" & SUBSTITUTE(A1, "#", "</s><s>") & "</s></t>", "//s"))}

Update April 2022: Use new TEXTSPLIT function.

like image 173
Vafā Sarmast Avatar answered Oct 03 '22 19:10

Vafā Sarmast