在没有VBA的Excel中拆分字符串(单元格)(例如,用于数组公式) [英] Split a string (cell) in Excel without VBA (e.g. for array formula)

查看:151
本文介绍了在没有VBA的Excel中拆分字符串(单元格)(例如,用于数组公式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Excel电子表格中包含分隔字符串的数据。为了简单起见,想到像4#8#10这样的东西,随意的数量。



有没有办法将其拆分成数组以用于数组公式?例如,像SUM(SplitStr(A1,#))。 (这不行 - 它只是返回4。)



有没有一个很好的方法呢?我的理想解决方案将是一个数组,就像用户输入{4,8,10}用于数组公式一样。



我的工作表的应用程序不允许使用基于分隔符的文本列,并对其进行求和。如果可能,我宁愿不使用VBA,因为我不会是表单的主要消费者。



谢谢,
特里

解决方案

条目4,8,10你可以使用以下的东西:

  = SUMPRODUCT(1 * TRIM(MID(SUBSTITUTE(A1, #,REPT(,99)),(ROW(OFFSET($ A $ 1 ,,,LEN(A1)-LEN(SUBSTITUTE(A1,#,))+ 1)) -  1)* 99 +((ROW(OFFSET($ A $ 1 ,,, LEN(A1)-LEN(SUBSTITUTE(A1,#,))+ 1)))= 1),99)))

返回的数组是一个文本数组,因此开始的 1 * 一种将其转换为数字的方法



此部分:

  TRIM (MID(SUBSTITUTE(A1,#,99)),(ROW(OFFSET($ A $ 1 ,,,LEN(A1)-LEN(SUBSTITUTE(A1,#,)) 1)) -  1)* 99 +((ROW(OFFSET($ A $ 1 ,,, LEN(A1)-LEN(SUBSTITUTE(A1, #, ))+ 1)))= 1), 99))

返回数组:

  {4;8;10} 

和1 *之前:

  {4; 8; 10} 


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

解决方案

To sum the entries 4,8,10 you could use something like:

=SUMPRODUCT(1*TRIM(MID(SUBSTITUTE(A1,"#",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(A1)-LEN(SUBSTITUTE(A1,"#",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(A1)-LEN(SUBSTITUTE(A1,"#",""))+1)))=1),99)))

The array that is returned is a text array, so the 1* at the beginning is one way to convert them to numbers

This part:

TRIM(MID(SUBSTITUTE(A1,"#",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(A1)-LEN(SUBSTITUTE(A1,"#",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(A1)-LEN(SUBSTITUTE(A1,"#",""))+1)))=1),99))

returns the array:

{"4";"8";"10"}

And with 1* before it:

{4;8;10}

这篇关于在没有VBA的Excel中拆分字符串(单元格)(例如,用于数组公式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆