我正在尝试编写代码(如下),以便在单击切换按钮时取消隐藏行。但是,其中有几行应该根据另一个单元格进行更新,并根据该单元格值隐藏某些行。下面的代码有效,但行不会自动更新,我需要单击切换按钮来隐藏然后取消隐藏行。有没有办法让它动态链接,以便它自动更新要隐藏的行?谢谢
Dim xAddress As String
xAddress = "55:136"
If Progress.Value Then
Application.ActiveSheet.Rows(xAddress).Hidden = False
If Range("I24").Value = "Yes" Then
Rows("92:102").EntireRow.Hidden = False
Rows("103:110").EntireRow.Hidden = True
ElseIf Range("I24").Value = "No" Then
Rows("92:102").EntireRow.Hidden = True
Rows("103:110").EntireRow.Hidden = False
End If
Else
Application.ActiveSheet.Rows(xAddress).Hidden = True
End If
答案1
如果Progress
是 Sheet1 上的切换按钮以及所有范围,请将其放置在 Sheet1 模块中
Option Explicit
Private Sub Progress_Click()
Dim rngI24 As Boolean
rngI24 = Me.Range("I24").Value2 = "Yes"
Me.Rows("55:136").Hidden = Me.Progress.Value
Me.Rows("92:102").Hidden = Not rngI24
Me.Rows("103:110").Hidden = rngI24
End Sub