Need a formula to return header if cell is not blank and concatenate the header names separated by comma

bb19august

New Member
Joined
Feb 1, 2019
Messages
18
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Car[/TD]
[TD]Bus[/TD]
[TD]Train[/TD]
[TD]Result[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]1[/TD]
[TD][/TD]
[TD]Car, Bus[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]2[/TD]
[TD]2[/TD]
[TD]Bus, Train[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]No[/TD]
[TD]Car, Train[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]3[/TD]
[TD][/TD]
[TD]Car, Bus[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD][/TD]
[TD]Yes[/TD]
[TD]Car, Train[/TD]
[/TR]
</tbody>[/TABLE]

Request your help to have a formula in excel to get a result as shown above. Cells could have numbers or blanks or text. if there is any number/text in any cell(s)the header(s) has to copied and concatenated and separated by comma.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
In D2 copied down
=TRIM(SUBSTITUTE(IF(A2<>"",A$1,",")&IF(B2<>"",", "& B$1,"")&IF(C2<>"",", "&C$1," "),",,",""))

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td]Car[/td][td]Bus[/td][td]Train[/td][td]Result[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]
1​
[/td][td]
1​
[/td][td][/td][td]Car, Bus[/td][td]=TRIM(SUBSTITUTE(IF(A2<>"",A$1,",")&IF(B2<>"",", "& B$1,"")&IF(C2<>"",", "&C$1," "),",,",""))[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td][/td][td]
2​
[/td][td]
2​
[/td][td]Bus, Train[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]
1​
[/td][td][/td][td]No[/td][td]Car, Train[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]
7​
[/td][td]
3​
[/td][td][/td][td]Car, Bus[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]
10​
[/td][td][/td][td]Yes[/td][td]Car, Train[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
7
[/td][td][/td][td][/td][td]Yes[/td][td]Train[/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet2[/td][/tr][/table]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top