简体   繁体   中英

SUM of multiple columns text in Excel

Is the first time writing a command in excel so I have no particular idea what I'm doing.

As you can see from the image I'm trying to get in the "All Stores" column all the Stores that have the "X" in them.

At the moment the command that I'm using is displaying the output of the first cell where it finds an "X".

I have looked at some examples that I found on this topic, but I didn't find something concrete. I've tried to do it with "SUMIF" and also I've tried to use "&" in from and after "B2", "C2", "D2", but all I got was an error.

Everything that I found on this topic was how to combine numbers.

In this particular example the expected result would be "Store1, Store3".

Thank you for your support!

产品商店示例

Yyou could use the following:

=TEXTJOIN(", ",TRUE,IF(B2="x",B$1,""),IF(C2="x",C$1,""),IF(D2="x",D$1,""))

And populate down for other products

Though it could get unwieldy if you have a lot of stores. I'm pretty sure someone else will come up with a more clever answer, but I can't think of anything else at the moment.

In E2 enter the array formula :

=CHOOSE(COUNTA(B2:D2)+1,"",INDEX(B$1:D$1,MATCH("x",B2:D2,0)),TEXTJOIN(", ",TRUE,IF(B2:D2="x",B$1:D$1,"")),"All stores")

在此处输入图片说明

Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key. If this is done correctly, the formula will appear with curly braces around it in the Formula Bar.

The logic is:

在此处输入图片说明

First of all, I image you have over several columns that you want to consider. SO you can get this date in a new worksheet by replacing "x" or a mark of choice using below formula: =IF(A2<>"", A$1, "") just autofill to get all the values in the new worksheet.

Now focussing on the new worksheet. eg 新工作表数据

Apply below formula to get the required result

=IF(COUNTA(H2:J2)-COUNTBLANK(H2:J2)=COLUMNS(H2:J2),"All Stories",TEXTJOIN(",",TRUE,H2:J2))

You can try this array formula:

=IFERROR(TEXTJOIN(",",TRUE,INDEX($A$1:$F$1,1,AGGREGATE(15,6,1/(B2:F2="X")*COLUMN(B2:F2),N(IF(1,ROW(INDIRECT("1:"&COUNTA(B2:F2)))))))),"")

To enter/confirm an array formula , hold down ctrl + shift while hitting enter . If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.

在此处输入图片说明

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