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
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.
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.
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.
Use XML functionality:
={SUM(FILTERXML("<t><s>" & SUBSTITUTE(A1, "#", "</s><s>") & "</s></t>", "//s"))}
Update April 2022: Use new TEXTSPLIT function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With