如何通过使用超链接(或通过将宏分配给超链接)来扩展 Excel 中的组

How to expand a group in Excel by using Hyperlink(or by maybe assigning Macro to Hyperlink)

我的 sheet 顶部有一个 table,而这个 table 有不同的部分名称。 我想插入一个指向这些部分名称的超链接,以便在我单击它们时打开下面的组。

Please Refer to the view of my table and sections as default (Collapsed)

我可以创建一个宏:

Expands all groups
Goes to the Section that I clicked,
Collapses all groups
Only opens the group on active cell, 

但是将此宏分配给 ~20 个不同的部分会增加文件大小。

经过一些搜索,我在 SO 上找到了这个:Excel: Assign a macro to a hyperlink? 那么也许有一种方法可以连接这两种方法?

如何解决?

我建议使用 "group" table 和您需要的任何汇总创建主 sheet。随后的 sheet 可能包含所有 "section" 数据。这具有更具可扩展性的额外好处。

是否绝对有必要将所有信息都放在同一个 sheet 上?这就是为什么 Excel 有多个 sheet 的原因。使用多个 sheet 还可以让您使用标准超链接。

但是,如果您想要 VBA 拉近距离,请考虑以下代码。这从活动单元格中获取值,然后搜索具有该值的下一个单元格。如果包含找到的单元格的部分被折叠,它会展开它,反之亦然。

Sub OpenSection()

Dim x As String
x = ActiveCell.Value

Dim y As String
y = Cells.Find(What:=(x), After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Address
'Range("b1").Value = y

With ActiveSheet
    With .Range(y).EntireRow
        If .ShowDetail = False Then
            .ShowDetail = True
        Else
            .ShowDetail = False
        End If
    End With
End With
End Sub