Grouping based on a condition

jschrock

New Member
Joined
Oct 5, 2011
Messages
47
So, I have a list of Yes/No questions and what I am trying to do is create a string of the terms that have a Y beside them. For example in the data below, I would like the cell to return Agitated, Angry, Depressed and I will reference that in a different part of a sheet. I would like for this to be dynamic, so if I put a 'Y' beside Apathetic, the string would read Agitated, Angry, Apathetic, and Depressed. I hope that makes sense. Here is the data:

[TABLE="width: 185"]
<tbody>[TR]
[TD]Mood:[/TD]
[TD]Yes/No[/TD]
[/TR]
[TR]
[TD]Agitated[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]Angry[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]Anxious[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Apathetic[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Depressed[/TD]
[TD]Y[/TD]
[/TR]
[TR]
[TD]Dysthymic[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Elevated[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Emotional[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fearful[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Manic[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Withdrawn[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Other:[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 185"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
I know I could do this with a bunch of If statements stacked together, but I would love to exclude or skip the items that are blank.

Thanks in advance!!!
 
Using VBA
Code:
Function jschrock(Rng As Range, Optional Crit As String = "Y")
    Dim Cl As Range
    Application.Volatile
    For Each Cl In Rng
        If Cl.Offset(, 1).Value = Crit Then jschrock = jschrock & Cl.Value & ", "
    Next Cl
    jschrock = Left(jschrock, Len(jschrock) - 2)
End Function
Used in the sheet like


Book1
AOAPAQ
25AgitatedYAgitated, Anxious, Apathetic, Dysthymic, Manic
26Angry
27AnxiousY
28ApatheticY
29Depressed
30DysthymicY
31Elevated
32Emotional
33Fearful
34ManicY
35Withdrawn
36Other:
Master
Cell Formulas
RangeFormula
AQ25=jschrock(AO25:AO36,"Y")
 
Upvote 0

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
another way with Pivot Table

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Yes/No[/td][td=bgcolor:#DDEBF7]Y[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Mood:[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]Agitated[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]Angry[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td]Depressed[/td][td][/td][/tr]
[/table]


or

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Yes/No[/td][td=bgcolor:#DDEBF7]Y[/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Mood:[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]Agitated[/td][td=bgcolor:#DDEBF7]Angry[/td][td=bgcolor:#DDEBF7]Depressed[/td][/tr]
[/table]
 
Last edited:
Upvote 0
Thank you guys so much for all of the help!!! It's always awesome to see how quickly everyone responds on here and is so helpful and creative.....best free subscription, ever!!!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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