A main checkbox that enable others checkbox

Hello i dont know how to made a checkbox that activate anothers checks box in a excel 2010.

enter image description here

What I mean If i check the first checkbox made falso al the other checkbox.

Upvotes: 0

Views: 179

Answers (1)

gembird
gembird

Reputation: 14053

short example here. Add check box named MasterCheckBox to your form. Use UserFormEnableEvents to suppres events in user form ... if u need.

Option Explicit
Private UserFormEnableEvents As Boolean

Private Sub UserForm_Initialize()
  UserFormEnableEvents = True
End Sub

Private Sub MasterCheckBox_Change(): On Error GoTo Err_handler
  Dim userFormControl As Control

  UserFormEnableEvents = False

  For Each userFormControl In Me.Controls
    If (TypeOf userFormControl Is MSForms.CheckBox And _
      userFormControl.Name <> MasterCheckBox.Name) Then
        userFormControl.Value = Not userFormControl.Value
    End If
  Next

Err_handler:
  If (Err.Number <> 0) Then MsgBox Err.Description
  UserFormEnableEvents = True
End Sub

enter image description here

Upvotes: 3

Related Questions