[英]Excel: Dividing comma separated single cell numbers
I have a string of numbers in a single Excel cell separated by commas, eg A2 = "4,3,2,7"
.我在一个用逗号分隔的 Excel 单元格中有一串数字,例如
A2 = "4,3,2,7"
。 I want a formula to be able to divide those number by 2 in cell B2
, eg B2 = "2,1,1,3"
(odd numbers should round down rather than up)我想要一个公式能够在单元格
B2
中将这些数字除以 2,例如B2 = "2,1,1,3"
(奇数应该向下取整而不是向上取整)
The formula needs to be able to account for:该公式需要能够说明:
- smaller or larger string of numbers - 更小或更大的数字串
- for both single and double digit numbers - 适用于一位数和两位数
- numbers that are even or odd - 偶数或奇数
- no VBA - 没有 VBA
- formula can use multiple columns but not the delimited text to columns feature (due to cell location) - 公式可以使用多列,但不能使用分隔文本到列功能(由于单元格位置)
I was able to get a formula to sum the string of numbers in A2
(4,3,2,7 = 16)
but not able to divide by 2. My formula to sum the string is below.我能够得到一个公式来对
A2
中的数字字符串求和(4,3,2,7 = 16)
,但不能除以 2。我对字符串求和的公式如下。 Any help is appreciated, thanks!任何帮助表示赞赏,谢谢!
{=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))))}
In your example, use this formula into cell B1
:在您的示例中,将此公式用于单元格
B1
:
=SUBSTITUTE(SUBSTITUTE(A1,",","000")/2,"000",",")
Then result will be like this:然后结果将是这样的:
| A | B |
+---------+---------+
1| 4,2,6,8 | 2,1,3,4 |
2|
Well, This is my second attempt to solve(I hope) your problem.好吧,这是我第二次尝试解决(我希望)你的问题。 If your string is in cell
A2
, then put this code inot cell B2
:如果您的字符串在单元格
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))
It can be worked with up to 8 number string, as well as odd numbers.它可以处理多达 8 个数字字符串以及奇数。
Update更新
This formula can handle double digit numbers but it supports only from 1 to 4 string numbers(eg (25,5,36,48)):此公式可以处理两位数,但仅支持 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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.