Full Select and reverse selection of a CheckBox via VBA

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.