List column headers where value is true

JimSpringer

New Member
Joined
Apr 17, 2019
Messages
4
I have a list generated from another program of all of the locations one person worked at. It looks like this. The order of the locations is listed randomly:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Gary[/TD]
[TD]Linda[/TD]
[TD]Marissa[/TD]
[TD]Brad[/TD]
[TD]Xavier[/TD]
[/TR]
[TR]
[TD]Lincoln[/TD]
[TD]Wausau[/TD]
[TD]Annapolis[/TD]
[TD]Laredo[/TD]
[TD]Bethesda[/TD]
[/TR]
[TR]
[TD]Laredo[/TD]
[TD][/TD]
[TD]Bethesda[/TD]
[TD]Waco[/TD]
[TD]Annapolis[/TD]
[/TR]
[TR]
[TD]St Louis[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Wausau[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

I was able to get it into a format like this:
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]Brad[/TD]
[TD]Gary[/TD]
[TD]Linda[/TD]
[TD]Marissa[/TD]
[TD]Xavier[/TD]
[/TR]
[TR]
[TD]Annapolis[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]YES[/TD]
[TD]YES[/TD]
[/TR]
[TR]
[TD]Bethesda[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]YES[/TD]
[TD]YES[/TD]
[/TR]
[TR]
[TD]Laredo[/TD]
[TD]YES[/TD]
[TD]YES[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Lincoln[/TD]
[TD]NO[/TD]
[TD]YES[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]St Louis[/TD]
[TD]NO[/TD]
[TD]YES[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Waco[/TD]
[TD]YES[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[/TR]
[TR]
[TD]Wausau[/TD]
[TD]NO[/TD]
[TD]NO[/TD]
[TD]YES[/TD]
[TD]NO[/TD]
[TD]YES[/TD]
[/TR]
</tbody>[/TABLE]

What I need to generate is a list like this one:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Annapolis[/TD]
[TD]Bethesda[/TD]
[TD]Laredo[/TD]
[TD]Lincoln[/TD]
[TD]St Louis[/TD]
[TD]Waco[/TD]
[TD]Wausau[/TD]
[/TR]
[TR]
[TD]Marissa[/TD]
[TD]Marissa[/TD]
[TD]Brad[/TD]
[TD]Gary[/TD]
[TD]Gary[/TD]
[TD]Brad[/TD]
[TD]Linda[/TD]
[/TR]
[TR]
[TD]Xavier[/TD]
[TD]Xavier[/TD]
[TD]Gary[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Xavier[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


Ideally, I would generate it from the first table, without having to make the second one. I am stuck, however, on how to make this happen. It seems like it should be simple, but I can't get it to work. Asking for help.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
you can try PowerQuery aka Get&Transform

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Gary[/td][td=bgcolor:#5B9BD5]Linda[/td][td=bgcolor:#5B9BD5]Marissa[/td][td=bgcolor:#5B9BD5]Brad[/td][td=bgcolor:#5B9BD5]Xavier[/td][td][/td][td=bgcolor:#70AD47]Annapolis[/td][td=bgcolor:#70AD47]Bethesda[/td][td=bgcolor:#70AD47]Laredo[/td][td=bgcolor:#70AD47]Lincoln[/td][td=bgcolor:#70AD47]St Louis[/td][td=bgcolor:#70AD47]Waco[/td][td=bgcolor:#70AD47]Wausau[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Lincoln[/td][td=bgcolor:#DDEBF7]Wausau[/td][td=bgcolor:#DDEBF7]Annapolis[/td][td=bgcolor:#DDEBF7]Laredo[/td][td=bgcolor:#DDEBF7]Bethesda[/td][td][/td][td=bgcolor:#E2EFDA]Marissa[/td][td=bgcolor:#E2EFDA]Xavier[/td][td=bgcolor:#E2EFDA]Brad[/td][td=bgcolor:#E2EFDA]Gary[/td][td=bgcolor:#E2EFDA]Gary[/td][td=bgcolor:#E2EFDA]Brad[/td][td=bgcolor:#E2EFDA]Linda[/td][/tr]

[tr=bgcolor:#FFFFFF][td]Laredo[/td][td][/td][td]Bethesda[/td][td]Waco[/td][td]Annapolis[/td][td][/td][td]Xavier[/td][td]Marissa[/td][td]Gary[/td][td][/td][td][/td][td][/td][td]Xavier[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]St Louis[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]Wausau[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
    Group = Table.Group(Unpivot, {"Value"}, {{"Count", each _, type table}}),
    TblList = Table.AddColumn(Group, "Custom", each Table.Column([Count],"Attribute")),
    Extract = Table.TransformColumns(TblList, {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    RC = Table.RemoveColumns(Extract,{"Count"}),
    Split = Table.SplitColumn(RC, "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2"}),
    Sort = Table.Sort(Split,{{"Value", Order.Ascending}}),
    Transpose = Table.Transpose(Sort),
    Promote = Table.PromoteHeaders(Transpose, [PromoteAllScalars=true])
in
    Promote[/SIZE]
 
Upvote 0
Anther option:-
Results start "G1".
Code:
[COLOR="Navy"]Sub[/COLOR] MG17Apr20
[COLOR="Navy"]Dim[/COLOR] n [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ray [COLOR="Navy"]As[/COLOR] Variant, Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] K [COLOR="Navy"]As[/COLOR] Variant, P [COLOR="Navy"]As[/COLOR] Variant, c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
 Ray = Cells(1).CurrentRegion
[COLOR="Navy"]With[/COLOR] CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
[COLOR="Navy"]For[/COLOR] Ac = 1 To UBound(Ray, 2)
   [COLOR="Navy"]For[/COLOR] n = 2 To UBound(Ray, 1)
   [COLOR="Navy"]If[/COLOR] Not IsEmpty(Ray(n, Ac)) [COLOR="Navy"]Then[/COLOR]
        [COLOR="Navy"]If[/COLOR] Not .Exists(Ray(n, Ac)) [COLOR="Navy"]Then[/COLOR] .Add Ray(n, Ac), New Collection
                .Item(CStr(Ray(n, Ac))).Add CStr(Ray(1, Ac)), CStr(Ray(1, Ac))
        [COLOR="Navy"]End[/COLOR] If
   [COLOR="Navy"]Next[/COLOR] n
[COLOR="Navy"]Next[/COLOR] Ac

Ac = 6
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] K [COLOR="Navy"]In[/COLOR] .keys
    Ac = Ac + 1
    Cells(1, Ac) = K: c = 1
        [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] P [COLOR="Navy"]In[/COLOR] .Item(K)
            c = c + 1
            Cells(c, Ac) = P
        [COLOR="Navy"]Next[/COLOR] P
[COLOR="Navy"]Next[/COLOR] K

[COLOR="Navy"]End[/COLOR] With
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
    Group = Table.Group(Unpivot, {"Value"}, {{"Count", each _, type table}}),
    TblList = Table.AddColumn(Group, "Custom", each Table.Column([Count],"Attribute")),
    Extract = Table.TransformColumns(TblList, {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    RC = Table.RemoveColumns(Extract,{"Count"}),
    Split = Table.SplitColumn(RC, "Custom", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Custom.1", "Custom.2"}),
    Sort = Table.Sort(Split,{{"Value", Order.Ascending}}),
    Transpose = Table.Transpose(Sort),
    Promote = Table.PromoteHeaders(Transpose, [PromoteAllScalars=true])
in
    Promote[/SIZE]
[/QUOTE]
:-o Jaw on the floor. I did not know about any of this! Thank you!

One thing I can't quite figure out - the query winds up returning only two rows. The real table I'm using is quite a bit larger, but if there are, say, fourteen sales reps in a city, it stops after the first two of them. So for an example, in a column where six people are assigned to Chicago, what I see is:

[TABLE="width: 500"]
<tbody>[TR]
[TD]Chicago[/TD]
[/TR]
[TR]
[TD]Anne[/TD]
[/TR]
[TR]
[TD]Brenda[/TD]
[/TR]
</tbody>[/TABLE]


Is there something I could tweak to get the missing reps listed?
 
Upvote 0
This is blowing my mind. I did not know how to do any of this, and it is so much fun. I wasted a day trying to figure out how do do this with MATCH/INDEX. My world is expanded.

Thank you both!
 
Upvote 0
so try this

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table7"]}[Content],
    Unpivot = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
    Group = Table.Group(Unpivot, {"Value"}, {{"Count", each _, type table}}),
    TblList = Table.AddColumn(Group, "Custom", each Table.Column([Count],"Attribute")),
    Extract = Table.TransformColumns(TblList, {"Custom", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    RC = Table.RemoveColumns(Extract,{"Count"}),
    DelimiterCount = Table.AddColumn(RC, "CountDelimiters", each List.Count(Text.Split([Custom],","))-1),
    MaxCount = List.Max(DelimiterCount[CountDelimiters])+1,
    Split = Table.SplitColumn(RC, "Custom", Splitter.SplitTextByDelimiter(","),MaxCount),
    Sort = Table.Sort(Split,{{"Value", Order.Ascending}}),
    Transpose = Table.Transpose(Sort),
    Promote = Table.PromoteHeaders(Transpose, [PromoteAllScalars=true])
in
    Promote[/SIZE]

or post more representative example ;)
 
Last edited:
Upvote 0
I don't see your solution so I can't say too much ;)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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