![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Portland, OR USA
Posts: 1,374
|
This should give you an idea. Hope it helps!
Code:
Private Sub CheckBox1_Change()
Dim ctl As Control
If CheckBox1 Then
For Each ctl In Me.Controls
If ctl.Name <> "CheckBox1" Then
Controls(ctl.Name).Enabled = True
ctl = True
End If
Next
Else
For Each ctl In Me.Controls
If ctl.Name <> "CheckBox1" Then
Controls(ctl.Name).Enabled = False
End If
Next
End If
End Sub
|
|
|
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks RH -
That was the hint I needed. "Controls(ctrl.Name).Enabled" did the trick. Thanks! |
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|