gpt4 book ai didi

vba - Button.Visible=False 在 VBA 中不起作用

转载 作者:行者123 更新时间:2023-12-04 20:15:07 26 4
gpt4 key购买 nike

我有一个启用宏的工作簿,过去它一直运行良好,但自从我更新 Windows 后,宏导致工作簿崩溃,给我一个错误“运行时错误'424':需要对象。”我似乎无法弄清楚为什么我的代码不再工作。这是我的代码。

Private Sub Worksheet_Change(ByVal Target As Range)
'Rage Button
If Cells(1, 12).Value = "Barbarian" Then 'CHANGE THE CELL TO THE ADRESS OF THE TRIGGER CELL
Rage.Visible = True 'CHANGE TO THE NAME OF THE BUTTON
Else
Rage.Visible = False 'CHANGE TO THE NAME OF THE BUTTON
End If

'Raging Brutality
If Cells(1, 12).Value = "Barbarian" Then
If WorksheetFunction.CountIf(Range(Cells(40, 1), Cells(61, 1)), "Raging Brutality") Then
Brutality.Visible = True
Else
Brutality.Visible = False
End If
Else
Brutality.Visible = False
End If
'Sneak Button
If Cells(1, 12).Value = "Rogue" Then 'CHANGE THE CELL TO THE ADRESS OF THE TRIGGER CELL
Sneak.Visible = True 'CHANGE TO THE NAME OF THE BUTTON
Else
Sneak.Visible = False 'CHANGE TO THE NAME OF THE BUTTON
Cells(25, 7).Value = 0
End If
End Sub

最佳答案

不是您特定问题的答案,而是因为 Visible是一个 bool 属性,您的代码可以减少:

Private Sub Worksheet_Change(ByVal Target As Range)

Rage.Visible = (Cells(1, 12).Value = "Barbarian")

Brutality.Visible = (Cells(1, 12).Value = "Barbarian" And _
WorksheetFunction.CountIf( _
Cells(40, 1).Resize(22,1), "Raging Brutality") > 0)

Sneak.Visible = (Cells(1, 12).Value = "Rogue")

If Not Sneak.Visible Then Cells(25, 7).Value = 0

End Sub

关于vba - Button.Visible=False 在 VBA 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28843593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com