2

I'm trying to build an Excel where the User selects from a range of checkboxes at the start (in a groupbox), each checkbox would reveal a new possible selection of checkboxes (either listbox or groupbox, whichever you think more appropriate) and then based on their final selections, generate/reveal the relevant tabs for them to read.

I'm having difficulty getting a Select/Deselect all button in there. This is what I'm trying so far, without much luck. If anyone could help I'd be very grateful.

Sub Tickall()

Dim CB As CheckBox
Dim OB As OptionButton
If ActiveSheet.OB.GroupBox.GroupBox1.CheckBoxes("Check Box 21").Value Then
    For Each CB In ActiveSheet.OB.GroupBox1.GroupBox1.CheckBoxes
        If CB.name <> ActiveSheet.OB.GroupBox1.CheckBoxes("Check Box 21").name Then
            CB.Value = True
        End If
    Next CB
End If
End Sub

2 Answers 2

1

GroupBoxes doesn't appear to have a Controls property to For Each. The only way I could see to determine if a CheckBox is within a GroupBox is to check if it's physically within it. I hope that's not the right answer and there's some more elegant way, but here's an example anyway

Public Sub TickAll()

    Dim gb As GroupBox
    Dim cb As CheckBox
    Dim cbAll As CheckBox

    Set gb = Sheet1.GroupBoxes(1)
    Set cbAll = Sheet1.CheckBoxes("Check Box 6")

    For Each cb In Sheet1.CheckBoxes
        If IsInGroupBox(cb, gb) Then
            cb.Value = cbAll.Value
        End If
    Next cb

End Sub

Public Function IsInGroupBox(ByRef cb As CheckBox, ByRef gb As GroupBox)

    IsInGroupBox = cb.Top > gb.Top And _
        cb.Top < gb.Top + gb.Height And _
        cb.Left > gb.Left And _
        cb.Left < gb.Left + gb.Width

End Function
0

Untested but I believe this is what you're looking for

ActiveSheet.CheckBoxes.Value = xlOff


ActiveSheet.CheckBoxes.Value = xlOn
3
  • How do I limit this effect to only the groupbox the "all" checkbox is in? I dont want the generated checkboxes to select all the options in the first one (and vice versa)
    – Cylen
    Aug 26, 2015 at 14:36
  • Are you saying for example you have three groups of checkboxes and the select/deselect all should only affect one of the groups?
    – mrbungle
    Aug 26, 2015 at 14:41
  • So CheckBox 1 has options, Colours, Numbers and Shapes in it, Checkbox 2 has Red Yellow Green, Checkbox 3 has One Two Three and Checkbox 4 has Square Triangle Circle, I want each one to have the option of select all items within each checkbox separately. From the selections the user makes, appropriate tabs will be revealed (Red Circle One, for example), and also to toggle it off, so if they select all, then they can uncheck it to deselect all
    – Cylen
    Aug 26, 2015 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.