Search code examples
exceltextjoin

Excel : Columns by row value


Is there a method without using macro or script, to get this result?

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

I need to concatenate COLUMN'S NAME for each "X" on rows.


Solution

  • In F2 enter the array formula:

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

    and copy down:

    enter image description here

    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.