我正在尝试编写代码以根据单元格值使多个按钮可见
我有 10 个命令按钮都是不可见的,我只想显示第一个 x x 是“Sheet1”中单元格“A1”的值(将从 1 到 10)命令按钮名称是默认名称(CommandButton4、CommandButton5、.. . , 命令按钮 13)
注意:我正在使用工作表而不是用户表单
这是我的代码,但我需要更短、更专业、更高效的代码
Private Sub CommandButton15_Click()
Dim i As Long
Dim CommandButton() As Variant
Application.ScreenUpdating = False
CommandButton = Array("CommandButton4", "CommandButton5", "CommandButton6", "CommandButton7", "CommandButton8", "CommandButton9", "CommandButton10", "CommandButton11", "CommandButton12", "CommandButton13")
For i = LBound(CommandButton) To LBound(CommandButton) + Sheet1.Range("A1").Value - 1
Sheet1.Shapes(CommandButton(i)).Visible = True
Next i
Application.ScreenUpdating = True
End Sub
需要你的帮助请