Home > Net >  Detect if a single group is open/close and close/open it
Detect if a single group is open/close and close/open it

Time:09-20

I know how to close all the groups at once using outline in the VBA like this:

'''' Close outline groups.
With sh.Outline
    .ShowLevels _
        RowLevels:=1, _
        ColumnLevels:=1
End With

I also know how to open all the groups at once using outline in the VBA like this:

'''' Open outline groups.
With sh.Outline
    .ShowLevels _
        RowLevels:=2, _
        ColumnLevels:=2
End With

But, how on earth can I open/close a single group!? And how do I detect if it is opened/closed!?

CodePudding user response:

You can use these two code snippets as starting point:

Public Function isCollapsed(c As Range) As Boolean
isCollapsed = c.EntireRow.ShowDetail
End Function


Public Sub collapse(c As Range)
With c.EntireRow
    If .ShowDetail = False Then
        .ShowDetail = True
    End If
End With
End Sub

You pass the cell which you want to check to the sub/function

  •  Tags:  
  • vba
  • Related