Here's what I did with your sample. It's only starting point. You may want to modify as needed.
Set up:
1: Data validation source range: S2:S5 (S5 for blank)
2: Added empty row after each grouping (needed to break each groups)
3: Formula in T2:T4 to find empty rows in column (each break).
In T2. Confirmed as array (CTRL + SHIFT + ENTER). Copied down.
=SMALL(IF($C$11:$C$43="",ROW($C$11:$C$43)),ROW(A1))
4: In D3 (beside validation cell) following formula
5: In standard module following code. Rows(#).ShowDetail is used to control individual group.
Sub ShowHideGroup(ws As Worksheet, rVal As Long)
Dim i As Integer
myArray = ws.Range("T2:T" & ws.Cells(Rows.Count, "T").End(xlUp).Row)
For i = 1 To UBound(myArray, 1)
If myArray(i, 1) = rVal And ws.Rows(myArray(i, 1)).ShowDetail <> True Then
ws.Rows(rVal).ShowDetail = True
ElseIf myArray(i, 1) <> rVal And ws.Rows(myArray(i, 1)).ShowDetail = True Then
ws.Rows(myArray(i, 1)).ShowDetail = False
End If
Next i
End Sub
6: In Worksheet module (for sheet1 in this case) Me = Activesheet, RowLevels:=2 will expand all, :=1 will collapse all.
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C3")) Is Nothing Then
If Target.Value = "" Then
Me.Outline.ShowLevels RowLevels:=2
Else
Call ShowHideGroup(Target.Parent, Target.Offset(, 1).Value)
End If
End If
End Sub
See attached sample.
Bookmarks