G
Guest
Guest
Problem: I need to make a loop to enable/disable 20 checkboxes on a Userform when Checkbox1.value changes.
The code changes remaining checkbox values to TRUE when Checkbox1 is "checked." Can't seem to use the same technique for "disable" - Ctrl.disable didn't work. Don't want to have 20 lines of code to disable the checkboxes. Is there a way to condense the last code lines in a loop?
Private Sub checkbox1_change()
If CheckBox1.Value = True Then
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
ctrl.Value = True
Next ctrl
End If
CheckBox2.Enabled = Not CheckBox1.Value
CheckBox3.Enabled = Not CheckBox1.Value
CheckBox4.Enabled = Not CheckBox1.Value
.
.
.
.
etc.
End Sub
The code changes remaining checkbox values to TRUE when Checkbox1 is "checked." Can't seem to use the same technique for "disable" - Ctrl.disable didn't work. Don't want to have 20 lines of code to disable the checkboxes. Is there a way to condense the last code lines in a loop?
Private Sub checkbox1_change()
If CheckBox1.Value = True Then
Dim ctrl As Control
For Each ctrl In UserForm1.Controls
ctrl.Value = True
Next ctrl
End If
CheckBox2.Enabled = Not CheckBox1.Value
CheckBox3.Enabled = Not CheckBox1.Value
CheckBox4.Enabled = Not CheckBox1.Value
.
.
.
.
etc.
End Sub