【问题标题】:Userform Checkbox: End if without block if error用户表单复选框:如果错误则没有阻止则结束
【发布时间】:2025-11-26 00:50:01
【问题描述】:

如果选中 VBA 用户表单复选框,则尝试让单元格 P3 显示“True”或“Yes”。

任何提示都会有所帮助。下面的代码导致编译错误:End If with no block if error。

If CheckBox1.Value = True _
Then Range("P3").Value = "True"
End If

【问题讨论】:

    标签: excel vba checkbox userform


    【解决方案1】:

    首先,如果您想在额外的行中添加then,您必须这样写

    If CheckBox1.Value = True _
    Then
        Range("P3").Value = "True"
    End If
    

    其次,CheckBox1.Value = True 也不是必需的,因为 CheckBox1.Valueboolean 类型。

    我喜欢的一段代码可能看起来像这样

    If CheckBox1.Value Then
        Range("P3").Value = "True"
    End If
    

    【讨论】:

    • 完美运行!谢谢。我会记住这一点,以备不时之需。我有点尴尬,我不知道这一点。我已经有一段时间没有从事 VBA 工作了。
    最近更新 更多