【问题标题】:Changing Value based upon if a button is clicked in Excel根据是否在 Excel 中单击按钮来更改值
【发布时间】:2022-08-15 23:22:13
【问题描述】:

我试图让一个按钮更改 Excel 中单元格的值,具体取决于按钮是真还是假。此时按钮可以被点击,它会自动变为false。如果再次单击该按钮,它应该变为真值,但它只是保持假。我对此进行了广泛的研究,但没有得出任何结论。任何帮助,将不胜感激。

Private Sub CommandButton1_Click()
If CommandButton1.Value = True Then
Range(\"H9\").Value = \"5\"
Else
Range(\"H9\").Value = \"0\"
End If
End Sub
  • 你想制作一个拨动开关吗?
  • 为什么不测试范围值(If Range(\"H9\").Value = \"0\" then

标签: excel vba


【解决方案1】:

拨动开关实现

Private Sub CommandButton1_Click()

    If InStr(1, CommandButton1.Caption, "OFF") Then
        Range("A1").Value = 5
        CommandButton1.Caption = "CommandButton1" & vbNewLine & "Current State: ON"
    Else
        Range("A1").Value = 0
        CommandButton1.Caption = "CommandButton1" & vbNewLine & "Current State: OFF"
    End If

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多