我的功能仅在调试模式下完全有效。但是,如果我从单元格=HYPERLINK("#MyHyperlink()", "yes")
中的超链接调用它,除了隐藏行之外,它几乎都会执行。这是我的代码。它放在Module1中。日Thnx
Function MyHyperlink()
Dim rng As Range, firstrow As Long, lastrow As Long
Set HyperlinkCollapseService = Selection
If ActiveCell.Value = "yes" Then
ActiveCell.Offset(0, -6).Value = True
firstrow = ActiveCell.row + 2
Set rng = Range(Cells(firstrow, 1).Address(), Cells(firstrow + 30, 1).Address())
lastrow = ActiveCell.row - 1 + Application.WorksheetFunction.Match("end", rng, 0)
Rows(firstrow & ":" & lastrow).EntireRow.Hidden = False
End If
If ActiveCell.Value = "no" Then
ActiveCell.Offset(0, -8).Value = False
firstrow = ActiveCell.row + 2
Set rng = Range(Cells(firstrow, 1).Address(), Cells(firstrow + 30, 1).Address())
lastrow = ActiveCell.row - 1 + Application.WorksheetFunction.Match("end", rng, 0)
Rows(firstrow & ":" & lastrow).EntireRow.Hidden = True
End If
End Function