仅验证一个复选框选择

时间:2019-03-05 01:44:29

标签: excel vba

我有两个复选框,我想避免在不选择其中一个的情况下记录表单,代码如下;

If CheckBox1.Value <> True Then
    If CheckBox2.Value = True Then
        Exit Sub
    Else
        MsgBox "You should select one option"
    End If
    Exit Sub
End If

此代码仅检索第一个复选框的结果,但我也想检索第二个复选框的结果,请为此提供您的建议,谢谢

4 个答案:

答案 0 :(得分:2)

这应该可以完成工作:-

If Not (CheckBox1.Value Or CheckBox2.Value) Then
    MsgBox "You should select one option"
End If

答案 1 :(得分:1)

另一个选择:

Select Case True
    Case CheckBox1.Value, CheckBox2.Value
    Case Else: Msgbox "Check At Least One Option"
End Select

答案 2 :(得分:0)

尝试以下代码:

If CheckBox1.Value <> True or CheckBox2.Value <> True Then
    MsgBox "You should select one option"
    Exit Sub
End If

答案 3 :(得分:-1)

如果CheckBox1.Value <> True和CheckBox2.Value <> True则         MsgBox“您应该选择一个选项”    其他         退出子    如果结束

相关问题