【发布时间】:2020-04-18 22:25:33
【问题描述】:
我有UserForm1,由四个Checkboxes组成:
CheckBox1 --> 主复选框 CheckBox2 --> 子复选框 CheckBox3 --> 子复选框 CheckBox4 --> 子复选框
现在,如果用户选中/取消选中 CheckBox1,sub CheckBoxes 2-4 会使用此 VBA 自动选中/取消选中:
Private Sub CheckBox1_Change()
If CheckBox1.Value = True Then
CheckBox2.Value = True
CheckBox3.Value = True
CheckBox4.Value = True
Else
CheckBox2.Value = False
CheckBox3.Value = False
CheckBox4.Value = False
End If
End Sub
这一切都很完美。
但是,现在我想实现这一点,以防sub CheckBoxes 2-4 之一被取消选中,main checkbox 也会自动取消选中,而不会取消选中另一个sub CheckBoxes.
示例:
用户首先单击CheckBox1,然后自动检查Checkboxes 2-4。
然后用户取消选中Checkbox2,CheckBox1 自动取消选中,而Checkbox 3-4 保持选中状态。
类似这样的:
Sub Check_Uncheck()
If any of Checkbox 2-4 is unchecked then
only uncheck CheckBox1 but do not change any other sub CheckBox
End
【问题讨论】: