Join Header Text into separate cells based on conditions of data below headers.

Markalon

New Member
Joined
Aug 22, 2014
Messages
11
Hi all. Need some help here. What I have:


ModelOptionAB1234
FALSETRUEFALSETRUEFALSEFALSE
TRUETRUETRUEFALSEFALSETRUE
TRUEFALSEFALSEFALSETRUEFALSE
FALSETRUETRUETRUEFALSETRUE

<tbody>
</tbody>

Need to comma delimit groupings of Models and Options based on True False condition. So, what I want:

ModelOptionAB1234
B2FALSETRUEFALSETRUEFALSEFALSE
A,B1,4TRUETRUETRUEFALSEFALSETRUE
A3TRUEFALSEFALSEFALSETRUEFALSE
B1,2,4FALSETRUETRUETRUEFALSETRUE

<tbody>
</tbody>


I hope this is clear enough. Any help would be greatly appreciated. And thanks in advance.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG22Aug03
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
[COLOR="Navy"]Dim[/COLOR] Str [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range(Range("c2"), Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    [COLOR="Navy"]For[/COLOR] Ac = 1 To 2
        [COLOR="Navy"]If[/COLOR] Dn(, Ac) = True [COLOR="Navy"]Then[/COLOR] Str = Str & ", " & Cells(1, Ac + 2)
    [COLOR="Navy"]Next[/COLOR] Ac
        Dn.Offset(, -2).Value = Mid(Str, 2)
        Str = ""
    [COLOR="Navy"]For[/COLOR] Ac = 3 To 6
        [COLOR="Navy"]If[/COLOR] Dn(, Ac) = True [COLOR="Navy"]Then[/COLOR] Str = Str & ", " & Cells(1, Ac + 2)
    [COLOR="Navy"]Next[/COLOR] Ac
        Dn.Offset(, -1).Value = Mid(Str, 2)
        Str = ""
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
For Model you could use the following formula (and fill down):
=IF(AND(TEXT(C2,0)="TRUE",TEXT(D2,0)="TRUE"),$C$1&","&$D$1,IF(AND(TEXT(C2,0)="true",TEXT(D2,0)="false"),$C$1,IF(AND(TEXT(C2,0)="false",TEXT(D2,0)="true"),$D$1,IF(AND(TEXT(C2,0)="false",TEXT(D2,0)="false"),""))))


For the Option column, it gets slightly more complicated but you can either apply the same methodology as above but add more steps or check out adding a UDF here .
 
Upvote 0
Try this:-
Code:
[COLOR=Navy]Sub[/COLOR] MG22Aug03
[COLOR=Navy]Dim[/COLOR] Rng [COLOR=Navy]As[/COLOR] Range, Dn [COLOR=Navy]As[/COLOR] Range
[COLOR=Navy]Dim[/COLOR] Ac [COLOR=Navy]As[/COLOR] [COLOR=Navy]Integer[/COLOR]
[COLOR=Navy]Dim[/COLOR] Str [COLOR=Navy]As[/COLOR] [COLOR=Navy]String[/COLOR]
[COLOR=Navy]Set[/COLOR] Rng = Range(Range("c2"), Range("C" & Rows.Count).End(xlUp))
[COLOR=Navy]For[/COLOR] [COLOR=Navy]Each[/COLOR] Dn [COLOR=Navy]In[/COLOR] Rng
    [COLOR=Navy]For[/COLOR] Ac = 1 To 2
        [COLOR=Navy]If[/COLOR] Dn(, Ac) = True [COLOR=Navy]Then[/COLOR] Str = Str & ", " & Cells(1, Ac + 2)
    [COLOR=Navy]Next[/COLOR] Ac
        Dn.Offset(, -2).Value = Mid(Str, 2)
        Str = ""
    [COLOR=Navy]For[/COLOR] Ac = 3 To 6
        [COLOR=Navy]If[/COLOR] Dn(, Ac) = True [COLOR=Navy]Then[/COLOR] Str = Str & ", " & Cells(1, Ac + 2)
    [COLOR=Navy]Next[/COLOR] Ac
        Dn.Offset(, -1).Value = Mid(Str, 2)
        Str = ""
[COLOR=Navy]Next[/COLOR] Dn
[COLOR=Navy]End[/COLOR] [COLOR=Navy]Sub[/COLOR]
Regards Mick



Mick,

First, thank you for the reply. Second, I was thinking more along the lines of comparison formula(s). I'm not sure what to do with this code or how to use it. My apologies for my ignorance.
 
Upvote 0
For Model you could use the following formula (and fill down):
=IF(AND(TEXT(C2,0)="TRUE",TEXT(D2,0)="TRUE"),$C$1&","&$D$1,IF(AND(TEXT(C2,0)="true",TEXT(D2,0)="false"),$C$1,IF(AND(TEXT(C2,0)="false",TEXT(D2,0)="true"),$D$1,IF(AND(TEXT(C2,0)="false",TEXT(D2,0)="false"),""))))


For the Option column, it gets slightly more complicated but you can either apply the same methodology as above but add more steps or check out adding a UDF here .


This is fantastic, and what I was looking for, except for the fact that I kind of simplified my table a bit. For the models, I actually have 4 different mixes. For the options, I have about 30. Looks like this formula is developed with every combination possible, which as you said, would make it more complicated, especially for the 30+ options.
 
Upvote 0
Perhaps I should be a little more specific:

What I have:


ModelOptionMod1
Mod2
Op1
Op2
Op3
Op4
FALSETRUEFALSETRUEFALSEFALSE
TRUETRUETRUEFALSEFALSETRUE
TRUEFALSEFALSEFALSETRUEFALSE
FALSETRUETRUETRUEFALSETRUE

<tbody>
</tbody>


Need to comma delimit groupings of Models and Options based on True False condition. So, what I want:

ModelOptionMod1
Mod2
Op1
Op2
Op3
Op4
B2FALSETRUEFALSETRUEFALSEFALSE
A,B1,4TRUETRUETRUEFALSEFALSETRUE
A3TRUEFALSEFALSEFALSETRUEFALSE
B1,2,4FALSETRUETRUETRUEFALSETRUE

<tbody>
</tbody>



I actually have 4+ models, and 30+ options in this table.
 
Upvote 0
I think you need to use VBA in this case.
BTW MickG's code works well.
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,971
Members
449,059
Latest member
oculus

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