我想通过点击按钮来隐藏/取消隐藏行。我通过使用以下代码实现了这一点:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
omrade = ActiveCell.Row + 4 & ":" & ActiveCell.Row + 37
If Rows(omrade).EntireRow.Hidden = True Then
Rows(omrade).EntireRow.Hidden = False
Else
Rows(omrade).EntireRow.Hidden = True
End If
Exit Sub
End Sub
如果单元格被超链接到同一个单元格(例如,单元格D5被超链接到D5 - 这将切换第9行到第42行的可见性)。
但是,我有多个链接(> 100),我不想在超链接中手动输入每个Cell Reference。我尝试使用Hyperlink公式制作动态超链接,但我的VBA代码将无法运行。
编辑:试图澄清我的问题。
答案 0 :(得分:2)
尝试这样的事情:
Rows(omrade).EntireRow.Hidden = not Rows(omrade).EntireRow.Hidden
如果可见则会隐藏,如果隐藏则隐藏。
答案 1 :(得分:2)
试试这个:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim rngHyperlinkCell As Range
Dim omrade As Range
Set rngHyperlinkCell = Target.Range
Set omrade = rngHyperlinkCell.Parent.Rows(rngHyperlinkCell.Row + 4 & ":" & rngHyperlinkCell.Row + 37)
If omrade.EntireRow.Hidden = True Then
omrade.EntireRow.Hidden = False
Else
omrade.EntireRow.Hidden = True
End If
End Sub
答案 2 :(得分:2)
我想知道是否发布它与@Robin非常相似,并且还使用@Vityata使用的隐藏:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
Dim subAddress As Range
Dim omrade As Range
'Set subAddress = Range(Target.subAddress) 'Where the link looks at.
Set subAddress = Target.Range 'Where the link is.
With subAddress.Parent
Set omrade = .Range(.Cells(subAddress.Row + 4, 1), .Cells(subAddress.Row + 37, 1))
omrade.EntireRow.Hidden = Not omrade.EntireRow.Hidden
End With
End Sub