Excel:用逗号分隔的单个单元格数

时间:2016-11-19 05:56:27

标签: excel comma

我在一个Excel单元格中有一串数字,用逗号分隔,例如A2 = "4,3,2,7"。我希望公式能够在单元格B2中将这些数字除以2,例如B2 = "2,1,1,3"(奇数应该向下舍入而不是向上)

公式需要能够解释:
- 更小或更大的数字串
- 用于单位和双位数字
- 偶数或奇数的数字 - 没有VBA
- 公式可以使用多列,但不能使用分隔文本到列的功能(由于单元格位置)

我能够得到一个公式来对A2 (4,3,2,7 = 16)中的数字串求和,但不能除以2.我的公式对字符串求和如下。感谢任何帮助,谢谢!

{=SUM(IF(ISERR(VALUE(MID(A2,ROW($A$1:OFFSET($A$1,LEN(A2)-1,0‌​)),1))),0,VALUE(MID(‌​A2,ROW($A$1:OFFSET($‌​A$1,LEN(A2)-1,0)),1)‌​)))}

2 个答案:

答案 0 :(得分:5)

在您的示例中,将此公式用于单元格B1

=SUBSTITUTE(SUBSTITUTE(A1,",","000")/2,"000",",")

然后结果将是这样的:

 |    A    |    B    |
 +---------+---------+  
1| 4,2,6,8 | 2,1,3,4 |
2|

答案 1 :(得分:0)

嗯,这是我第二次尝试解决(我希望)你的问题。如果您的字符串位于单元格A2中,请将此代码放入单元格B2

=LEFT(IFERROR(ROUNDDOWN(MID(A2,1,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,3,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,5,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,7,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,9,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,11,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,13,1)/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,15,1)/2,0),""),LEN(A2))

最多可以使用8个数字字符串,以及奇数。

<强>更新

此公式可以处理两位数字,但它只支持1到4个字符串数字(例如(25,5,36,48)):

=LEFT(IFERROR(ROUNDDOWN(MID(A2,1,IFERROR(SEARCH(",",A2,1)-1,LEN(A2)))/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,SEARCH(",",A2,1)+1,IFERROR(SEARCH(",",A2,SEARCH(",",A2,1)+1)-SEARCH(",",A2,1)-1,LEN(A2)-SEARCH(",",A2,1)))/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1,IFERROR(SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)-SEARCH(",",A2,SEARCH(",",A2,1)+1)-1,LEN(A2)-SEARCH(",",A2,SEARCH(",",A2,1))))/2,0),"")&","&IFERROR(ROUNDDOWN(MID(A2,SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)+1,IFERROR(SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)+1)-SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)-1,LEN(A2)-SEARCH(",",A2,SEARCH(",",A2,SEARCH(",",A2,1)+1)+1)))/2,0),""),LEN(A2))