Reputation: 29
Another VBA dilemma for you.
I have checkbox1, checkbox2 and checkbox3. I would like checkbox2 and checkbox3 to be greyed out if checkbox1=true I have used a code similar for greying out a textbox
Private Sub CheckBox1_Click()
Dim en As Boolean
en = Not CheckBox1.Value
EnableControls Array(tbappgn, tbappfn), en
'utility sub: enable/disable controls
Private Sub EnableControls(cons, bEnable As Boolean)
Dim con
For Each con In cons
With con
.Enabled = bEnable
.BackColor = IIf(bEnable, vbWhite, RGB(200, 200, 200))
End With
Next con
End Sub
Just having an issue with getting the same code to work on other checkboxes.
Can add the checkbox numbers to the code above but I don't want that checkbox to be the trigger to grey/un grey the other checkboxes
something like this but with the correct terms.
Private Sub CheckBox11_Click()
Dim en As Boolean
en = Not CheckBox11.Value
EnableControls Array(checkbox12, checkbox13), en
Private Sub CheckBox15_Click()
Dim en As Boolean
en = Not CheckBox15.Value
EnableControls Array(checkbox16, checkbox17), en
Private Sub EnableControls(cons, bEnable As Boolean)
Dim con
For Each con In cons
With con
.Enabled = bEnable
.BackColor = IIf(bEnable, vbWhite, RGB(200, 200, 200))
End With
Next con
End Sub
Upvotes: 0
Views: 654
Reputation: 1060
Is this what you're asking for? When checkbox1 is true, the other will be grey... and vice versa...
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
CheckBox2.Enabled = False
CheckBox3.Enabled = False
Else
CheckBox2.Enabled = True
CheckBox3.Enabled = True
End If
End Sub
Upvotes: 1