Excel :按行值列

Excel : Columns by row value

有没有不使用宏或脚本的方法,得到这个结果?

Bus Line    L1  L2  L3  L4  Result
Stops                   
1               X       X   L2,L4
2                       X   L4
3           X       X       L1,L3

我需要为每行 "X" 连接列的名称。

使用数组版本的 TEXTJOIN()

=TEXTJOIN(",",TRUE,IF(B2:E2="x",$B:$E1,""))

作为数组公式,退出编辑模式时需要用Ctrl-Shift-enter确认,而不是回车。

您还可以使用辅助列。在 H2 中输入:

=IF(B2="X","," &B,"")

拖动超过 4 列并向下拖动数据的长度。

然后在F2中输入:

=MID(H2&I2&J2&K2,2,99)

另一个选项是结合了上述两个步骤的长公式:

=MID(IF(B2="X","," &B,"")&IF(C2="X","," &C,"")&IF(D2="X","," &D,"")&IF(E2="X","," &E,""),2,99)

F2输入数组公式:

=TEXTJOIN(",",TRUE,IF(B2:E2="X",$B:$E,""))

并抄下来:

数组公式必须用Ctrl+Shift+输入Enter 而不仅仅是 Enter 键。如果操作正确,公式将在公式栏中显示,并带有花括号。