简体   繁体   中英

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. I need to multiply each number by 1,2,3,4,5,6,7,8 in this exact particular order.

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)

eg 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

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)

And with 1,2,3,4,5,6,7,8 . there are only 6 results.

I have just recently started learning excel and any help would be very much appreciated.

With Office 365 we use FILTERXML and SUBSTITUTE to create an array of the numbers. Then with TEXTJOIN we put them back together into a string after using SEQUENCE to create an array of 1,2,3,... and multiplying. LET is used so we do not need to repeat the long 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)) . 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

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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