×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Select All Checkboxes on Excel worksheet

Select All Checkboxes on Excel worksheet

Select All Checkboxes on Excel worksheet

(OP)
Hello! I have an Excel worksheet with 6 checkboxes on them. The first checkbox is supposed to check all checkboxes when it is clicked. I have the code below:

Private Sub Checkbox0_Click()
If CheckBox0.Value = True Then
Dim i As Integer
For i = 1 To 5
    CheckBox(i).Value = True
Next i
End If
End Sub

However, on running it in VBA, it gives me a compile error saying "Sub or Function is not defined". What is the right syntax to loop each check box and make them all true?

RE: Select All Checkboxes on Excel worksheet

(OP)
Good to know CCG. Since there are only five other checkboxes, my code would only be two lines longer, as follows:

If Checbox0.Value = True Then
Checkbox1.Value = True
Checkbox2.Value = True
Checkbox3.Value = True
Checkbox4.Value = True
Checkbox5.Value = True
End If

Problem solved.

RE: Select All Checkboxes on Excel worksheet

Although impossible to create an a array of controls as SMMA says, it is possible to loop through a collection of controls on a worksheet.  For example

CODE

Private Sub CheckBox0_Click()
  For Each ct In Me.OLEObjects
    With ct.Object
      If .GroupName = "A" Then .Value = CheckBox0.Value
    End With
  Next ct
End Sub
In the sample I've given each of the checkboxes to be controled by checkbox0 the same groupname, "A"

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources