jnash67
asked on
Excel VBA Trap the Group and Outline expand/collapse (Show Detail / Hide Detail) events
How can I determine when the user has hit the [+] or [-] buttons in a grouping in a worksheet?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As Rory stated above, the only event you can trigger with a group collapse/expand action is the calculation event. To do so you need to use the SUBTOTAL function which is aware of whether or not rows are hidden. It is not aware of a column's visibility so this solution only works with grouped rows. To capture a collapse/expand action place a SUBTOTAL function anywhere on the worksheet that references the rows being monitored. For example, to monitor all rows use the formula below.
=SUBTOTAL(1,A:A)
To monitor rows 2 through 100 use the range A2:A100 instead of A:A. Anytime any of the rows in the specified range are collapsed or expanded the formula is recalculated and a calculation event is generated. To determine which group is visible and which is not, query the Hidden property of any row in each group as illustrated below.
If Rows(10).Hidden Then
MsgBox "Group is collapsed"
Else
MsgBox "Group is expanded"
End If
Kevin
=SUBTOTAL(1,A:A)
To monitor rows 2 through 100 use the range A2:A100 instead of A:A. Anytime any of the rows in the specified range are collapsed or expanded the formula is recalculated and a calculation event is generated. To determine which group is visible and which is not, query the Hidden property of any row in each group as illustrated below.
If Rows(10).Hidden Then
MsgBox "Group is collapsed"
Else
MsgBox "Group is expanded"
End If
Kevin
ASKER
Kevin, your first solution is exactly what I needed. I couldn't go the subtotal route because I don't have calculation set to automatic for the application in question.
ASKER
I have a follow-up question at: https://www.experts-exchange.com/questions/23527968/Excel-VBA-Set-the-image-of-a-Picture-object.html
ASKER
Regards,
Rory