I want to disable a checkbox when another checkbox is in excel

I want to check a box and check the box associated with it in Excel.

If you clear this check box, select the Disabled check box.

I tried so many things but couldn't find a solution. Can I do this without a script?

I have 76 checkboxes to work with. So is this possible without a script? TIA

+5


source to share


5 answers


With two ActiveX checkboxes, the code looks like this:

Private Sub CheckBox1_Click()

If CheckBox2.Enabled = True Then
    CheckBox2.Enabled = False
Else:
    CheckBox2.Enabled = True
End If

End Sub

      



It's simple, but it works.

+1


source


If you want the code to check and disable clicking on the second field then use the below code. If you uncheck the initial box, it will also enable and uncheck the second.



Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
    CheckBox2.Value = True
    CheckBox2.Enabled = False
Else
    CheckBox2.Value = False
    CheckBox2.Enabled = True
End If
End Sub

      

+1


source


more directly

Sub CheckBox1_Click()
 CheckBox2.Enabled = Not CheckBox2.Enabled
End Sub

      

+1


source


I believe you can use "OptionButton's". You don't need any code for them. But this way you can only check one of the 76. And what do you mean by "anchored checkbox"?

+1


source


Option Compare Database

Private Sub Ck1_Click()

If Ck1 = True Then
Ck2.Enabled = False
Ck3.Enabled = False
Else
Ck2.Enabled = True
Ck3.Enabled = True
End If

End Sub

Private Sub Ck2_Click()

If Ck2 = True Then
Ck1.Enabled = False
Ck3.Enabled = False
Else
Ck1.Enabled = True
Ck3.Enabled = True
End If

End Sub

Private Sub Ck3_Click()

If Ck3 = True Then
Ck1.Enabled = False
Ck2.Enabled = False
Else
Ck1.Enabled = True
Ck2.Enabled = True
End If

End Sub

      

0


source







All Articles