Excel 工作表\u计算以隐藏命令按钮
我在下面找到了Excel 工作表\u计算以隐藏命令按钮,excel,vba,Excel,Vba,我在下面找到了工作表\u Change的代码。但我的H29是公式=SUM。 如何将其更改为工作表\u Calculate,以便运行下面的宏 基本上我想要的是,如果H29被计算为等于20,显示按钮,否则隐藏它 Private Sub Worksheet_Change(ByVal Target As Range) Application.ScreenUpdating = False If Target = Range("H29") Then If Target.Value = "20" Then
工作表\u Change
的代码。但我的H29是公式=SUM
。
如何将其更改为工作表\u Calculate
,以便运行下面的宏
基本上我想要的是,如果H29被计算为等于20,显示按钮,否则隐藏它
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
If Target = Range("H29") Then
If Target.Value = "20" Then
Me.CommandButton1.Visible = True
Else
Me.CommandButton1.Visible = False
End If
Application.ScreenUpdating = True
End If
根据按钮类型,指示按钮的代码将不同。试试这个
Private Sub Worksheet_Calculate()
'ActiveX button
If Range("H29").Value = 20 Then
Sheets("Sheet1").CommandButton2.Visible = False
Else
Sheets("Sheet1").CommandButton2.Visible = True
End If
'Forms Button
If Range("H29").Value = 20 Then
Sheets("Sheet1").Shapes("CommandButton1").Visible = msoFalse
Else
Sheets("Sheet1").Shapes("CommandButton1").Visible = msoTrue
End If
End Sub
对不起,我问得太早了。决心
Private Sub Worksheet_Calculate()
'ActiveX button
Application.ScreenUpdating = False
If Range("H29").Value = 20 Then
Me.CommandButton1.Visible = True
Else
Me.CommandButton1.Visible = False
End If
Application.ScreenUpdating = True
End Sub
非常感谢。我也会复习。我设法用你的帮助解决了这个问题。如果你使用像
Me.CommandButton1.Visible=Range(“H29”).Value=20这样的东西,它就变成了一个简单的一行代码。