如何在 excel 中一键下钻数据?

How to drill down data in one single click in excel?

我有一年的进步table,其中一列包含(+)号,我想要的是当我点击(+) 从数字 8 到 15 的行将向下钻取数据(显示数据),在这种情况下,(+)符号将是(-)符号,然后重新单击(-)符号以向下钻取数据(隐藏数据)和(-) 又来了 (+)。我希望这个公式适用于整个 table 的每一行。注意:我的代码的问题只针对一行,但我想要所有的,所以有没有简单的方法来解决所有的行。

The Table when rows is Hidden

The Table when rows is Appeared

Trying Code

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Not Intersect(Target, Range("O:O")) Is Nothing And Target.Cells.CountLarge = 1 Then

If Range("A8:R15").EntireRow.Hidden = True Then

    Range("A8:R15").EntireRow.Hidden = False

Else
    Range("A8:R15").EntireRow.Hidden = True
End If
End If
End Sub

更新

Screenshot after using the correct Code

我在这里使用了双击事件:否则需要在单元格外单击并再次返回以反转 hide/unhide。

有点尴尬
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim rng As Range
    'exit if not in monitored column
    If Intersect(Target, Me.Range("O:O")) Is Nothing Then Exit Sub
    'check for +/-
    If Target.Value = "+" Or Target.Value = "-" Then
        Set rng = Target.Offset(1, 0).Resize(8).EntireRow
        rng.Hidden = Not rng.Hidden
        Target.Value = IIf(rng.Hidden, "+", "-") 'reset cell text
        Cancel = True 'don't enter edit mode in the clicked cell
    End If
End Sub