Reputation: 63
In Above excel sheet i need a formula which will extract that particular column name where "1" is present and enter that name in the corresponding cell. Example- In above Image each row corresponding to col "Tags" contain the column name whose corresponding cell contain "1".
Upvotes: 2
Views: 1106
Reputation: 19319
For a 4 column example you can use this:
=SUBSTITUTE(TRIM(IF(A2,$A$1,"")&" "&IF(B2,$B$1,"")&" "&IF(C2,$C$1,"")&" "&IF(D2,$D$1,""))," ",", ")
For 7 columns, just add additional IF
statements inside the TRIM
following the same pattern.
The formula relies on 1=TRUE
to keep it short. The result each IF
is followed by a space. The TRIM
gets rid of extra spaces left when no 1
occurs. Finally SUBSTITUTE
converts into
,
so you get a comma delimited list.
Note that:
TRIM strips extra spaces from text, leaving only single spaces between words and no space characters at the start or end of the text.
Upvotes: 2
Reputation: 108
Supposing your header range is A-K,
You could you use this formula from L2 onwards:
=IF(MID(TRIM(IF(A2=1,A$1,"")&IF(B2=1,", "&B$1,"")&IF(C2=1,", "&C$1,"")&IF(D2=1,", "&D$1,"")&IF(E2=1,", "&E$1,"")&IF(F2=1,", "&F$1,"")&IF(G2=1,", "&G$1,"")&IF(H2=1,", "&H$1,"")&IF(I2=1,", "&I$1,"")&IF(J2=1,", "&J$1,"")&IF(K2=1,", "&K$1,"")),1,2)=", ",MID(TRIM(IF(A2=1,A$1,"")&IF(B2=1,", "&B$1,"")&IF(C2=1,", "&$C$1,"")&IF(D2=1,", "&D$1,"")&IF(E2=1,", "&E$1,"")&IF(F2=1,", "&F$1,"")&IF(G2=1,", "&G$1,"")&IF(H2=1,", "&H$1,"")&IF(I2=1,", "&I$1,"")&IF(J2=1,", "&J$1,"")&IF(K2=1,", "&K$1,"")),3,1000),TRIM(IF(A2=1,A$1,"")&IF(B2=1,", "&B$1,"")&IF(C2=1,", "&C$1,"")&IF(D2=1,", "&D$1,"")&IF(E2=1,", "&E$1,"")&IF(F2=1,", "&F$1,"")&IF(G2=1,", "&G$1,"")&IF(H2=1,", "&H$1,"")&IF(I2=1,", "&I$1,"")&IF(J2=1,", "&J$1,"")&IF(K2=1,", "&K$1,"")))
This formula has a limit of 1000 character in column by the mid function. and it repeats 3 times the same formula because of the separator: ", " but if you dont mind the result format you can short it to one. just fill put 1 in columns and the column name will appear.
Hope this helps.
Upvotes: 0
Reputation: 2066
couldn't find a non vba solution for concatenating a range. So here is a UDF
Function conCatRange(ByVal criteriaRange As range, _
ByVal criteria As String, _
ByVal conRange As range, _
ByVal separator As String) As String
Dim c As range
conCatRange = ""
For i = 1 To conRange.Columns.Count
If (criteriaRange(1, i) = criteria) Then
conCatRange = conCatRange & conRange(1, i) & separator
End If
Next i
conCatRange = Left(conCatRange, Len(conCatRange) - 1)
End Function
if you want to add summary and parameter descriptions see this link How to put a tooltip on a user-defined function
Upvotes: 0