0

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.

Scott Craner
  • 148,073
  • 10
  • 49
  • 81
RetroMime
  • 387
  • 1
  • 8
  • 23
  • 1
    Can you demonstrate *any* effort at solving this yourself? – Scott Hunter Mar 12 '18 at 15:37
  • Yeah. I was trying to use MATCH, INDEX or LOOKUP. For example =MATCH("X";B1:E3;0) dosn't find anything. Orizzontal lookup search the first row and then get the row you want in the same column but I want the inverse. – RetroMime Mar 12 '18 at 15:45

2 Answers2

0

Use an array version of TEXTJOIN()

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

Being an array formula it needs to be confirmed with Ctrl-Shift-enter instead of Enter when exiting edit mode.

You can also use helper columns. In H2 put:

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

Drag over 4 columns and down the length of the data.

Then in F2 put:

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

enter image description here

The other option is a long formula that combines the two steps above:

=MID(IF(B2="X","," &B$1,"")&IF(C2="X","," &C$1,"")&IF(D2="X","," &D$1,"")&IF(E2="X","," &E$1,""),2,99)
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
0

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.

Gary's Student
  • 95,722
  • 10
  • 59
  • 99