简体   繁体   English

EXCEL:在单元格中乘以逗号分隔的个位数

[英]EXCEL: Multiplying comma separated single-digit numbers in a cell

I have a string of 8 single-digit numbers in a cell separated by commas.我在一个用逗号分隔的单元格中有一个 8 个个位数的字符串。 I need to multiply each number by 1,2,3,4,5,6,7,8 in this exact particular order.我需要按照这个确切的特定顺序将每个数字乘以 1,2,3,4,5,6,7,8。

If I have A2= a,b,c,d,e,f,g,h I need the result B2= (a*1),(b*2),(c*3),(d*4),(e*5),(f*6),(g*7),(h*8)如果我有A2= a,b,c,d,e,f,g,h我需要结果B2= (a*1),(b*2),(c*3),(d*4),(e*5),(f*6),(g*7),(h*8)

eg A2=1,2,3,4,5,6,7,8 => B2=1,4,9,16,25,36,49,64例如A2=1,2,3,4,5,6,7,8 => B2=1,4,9,16,25,36,49,64

I have worked up this formula -我已经制定了这个公式 -

=LEFT(MID(A2,1,1)*1&","&MID(A2,3,1)*2&","&MID(A2,5,1)*3&","&MID(A2,7,1)*4&","&MID(A2,9,1)*5&","&MID(A2,11,1)*6&","&MID(A2,13,1)*7&","&MID(A2,15,1)*8,LEN(A2))

It does work for the first few numbers but I think this is having trouble handling all the numbers.它确实适用于前几个数字,但我认为这在处理所有数字时遇到了麻烦。 It works fine if I put in 0,0,0,0,0,0,0,1如果我输入0,0,0,0,0,0,0,1它工作正常

But if I put in 0,0,0,0,0,2,2,2 , I get 0,0,0,0,0,12,14 (which is only 7 results)但是如果我输入0,0,0,0,0,2,2,2 ,我会得到0,0,0,0,0,12,14 (这只有 7 个结果)

And with 1,2,3,4,5,6,7,8 .1,2,3,4,5,6,7,8 there are only 6 results.只有 6 个结果。

I have just recently started learning excel and any help would be very much appreciated.我最近才开始学习 excel,任何帮助将不胜感激。

With Office 365 we use FILTERXML and SUBSTITUTE to create an array of the numbers.在 Office 365 中,我们使用 FILTERXML 和 SUBSTITUTE 创建数字数组。 Then with TEXTJOIN we put them back together into a string after using SEQUENCE to create an array of 1,2,3,... and multiplying.然后使用 TEXTJOIN 在使用 SEQUENCE 创建一个1,2,3,...的数组并相乘后,我们将它们重新组合成一个字符串。 LET is used so we do not need to repeat the long FILTERXML:使用了 LET,所以我们不需要重复长的 FILTERXML:

=LET(num,FILTERXML("<t><s>"&SUBSTITUTE(A2,",","</s><s>")&"</s></t>","//s"),TEXTJOIN(",",,num*SEQUENCE(COUNT(num))))

This version does not care how many numbers are in the string.此版本不关心字符串中有多少个数字。

在此处输入图像描述


The reason yours is doing what it is, is the LEFT(...,LEN(A2)) .你这样做的原因是LEFT(...,LEN(A2)) It is only returning the same number of characters as the original.它只返回与原始字符相同数量的字符。 Remove that part, it is not needed:删除该部分,不需要它:

=MID(A2,1,1)*1&"," &MID(A2,3,1)*2&","&MID(A2,5,1)*3&","&MID(A2,7,1)*4&","&MID(A2,9,1)*5&","&MID(A2,11,1)*6&","&MID(A2,13,1)*7&","&MID(A2,15,1)*8

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM