Regarding rows not in pivot tables ... It wasnβt my experience in Excel 2010 that ShowDetail ALWAYS evaluates to True. I thought it was, but I didnβt understand that I needed to be in the summary line for this property to work as expected. Secondly, I did not understand that the resulting row is by default under grouped rows. Testing for minimized / expanded mode became much clearer as soon as I changed this parameter to have a summary line over grouped lines (in the ribbon: data> outline, display box frame).
If my selected cell is in the summary row, ShowDetail evalutes returns True if grouped records are displayed, and False if they are not. The key for me was in the summary line to see that the behavior works this way. Having default child / grouped lines really threw me away.
Here's my macro that dynamically expands and collapses grouped records tied to a summary row when I select a cell in the summary row. And that makes my cell in the Bold column if the section expands. This macro does not run if I have selected more than one cell.
Note that protecting a worksheet prevents the expansion and collapse of cell groups. My worksheet is protected, so I take sheets to expand / collapse and then replay them. (Perhaps I can just protect or protect only the current sheet, not all).
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'TOGGLE SHOW/HIDE ROW If Target.Cells.Count = 1 Then If (Target.EntireRow.OutlineLevel = 1) And (Target.Offset(1, 0).EntireRow.OutlineLevel = 2) And _ (Target.Column < 15) Then Call Macros.ProtShts(False) Target.EntireRow.ShowDetail = Not Target.EntireRow.ShowDetail If Target.EntireRow.ShowDetail = True Then Range(Cells(Target.Row, 1), Cells(Target.Row, 14)).Font.Bold = True Else Range(Cells(Target.Row, 1), Cells(Target.Row, 14)).Font.Bold = False End If Call Macros.ProtShts(True) End If End If End Sub
Remember, I set my summary line above grouped entries. If the summary line is lower than the grouped entries (by default), then the reference to the offset line should be changed to -1, for example:
(Target.Offset(1, 0).EntireRow.OutlineLevel = 2)
source share