The Select and reverse selection of a checkbox can be controlled by VBA, which is common in some interactive reports with the following code:
1. Divided into two if judgments
Private Sub checkbox1_click () ' checkbox for Master control, by clicking on it to achieve a full selection or inverse selection
Dim B3 as Integer
Dim I as Integer
Dim B1 as Range
If Sheets (1). Checkbox1.value Then ' If the first if is judged as a condition of full selection
B3 = Sheets (1). Range ("H50"). End (Xlup). Row ' is used to solve the problem of data discontinuity
For i = 2 to B3
Sheets (1). OLEObjects ("checkbox" & i). Object.value = True
Next I
End If
If Sheets (1). Checkbox1.value = False Then ' If the first if is judged to be a condition of the reverse selection
B3 = Sheets (1). Range ("H50"). End (Xlup). Row
For i = 2 to B3
Sheets (1). OLEObjects ("checkbox" & i). Object.value = False
Next I
End If
End Sub
2. Make CheckBox1 the same as the rest of the check boxes, and the rest of the code, just change the For loop section as follows:
For i = 3 to Sheets (1). OLEObjects ("checkbox" & i). Object.value = Sheets (1). Checkbox1.value ' So long as CheckBox1 is selected, all check boxes in the loop body are selected, and vice versa
Next I
3. Determine by setting a Boolean value
Dim F As Boolean ' sets a Boolean variable
f = Sheets (1). Checkbox1.value ' assigns this variable to all checkboxes, so that they are kept in the same state at all times.
For i = 3 to 30
Sheets (1). OLEObjects ("checkbox" & i). Object.value = f
Next I
Full Select and reverse selection of a CheckBox via VBA