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:

Mood:Yes/No
AgitatedY
AngryY
Anxious
Apathetic
DepressedY
Dysthymic
Elevated
Emotional
Fearful
Manic
Withdrawn
Other:

<tbody>
</tbody>

<tbody>
</tbody>
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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
another way with Pivot Table

Yes/NoY
Mood:
Agitated
Angry
Depressed

or

Yes/NoY
Mood:
AgitatedAngryDepressed
 
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,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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