Consulting

Results 1 to 6 of 6

Thread: Solved: Easiest way to check/uncheck all checkboxes?

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location

    Unhappy Solved: Easiest way to check/uncheck all checkboxes?

    Hi, I have this crossposted on Mr. Excel:
    http://www.mrexcel.com/forum/showthread.php?t=331524

    I've got an embedded chart on a worksheet and it has 24 checkboxes (control toolbox, not form) corresponding to different devices. How would I go about linking another checkbox to select or unselect all the boxes?

    I know it could generally be something like:
    [VBA]
    Private Sub checkbox_Click()
    Select Case checkbox.Value
    Case True
    Make all the other checkboxes true
    Case False
    Make all the other checkboxes false
    End Select
    End Sub
    [/VBA]

    And how the heck do I refer to the checkboxes?!?

    Thanks!
    -Matt

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Private Sub CheckBox1_Click()
    Dim obj As OLEObject

    For Each obj In Me.OLEObjects

    If TypeName(obj.Object) = "CheckBox" Then

    If obj.Name <> "CheckBox1" Then

    obj.Object.Value = Me.CheckBox1.Value
    End If
    End If
    Next obj
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location
    Problem here is that, apparently, when using control toolbox checkboxes on an embedded chart, they are part of the Shapes collection.

  4. #4
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location
    Solved.

    [VBA]
    Sub MatchCheckbox()
    Dim s As Shape
    Dim i As Long
    Worksheets("Chart").ChartObjects(1).Activate
    With ActiveChart
    For i = 8 To 31
    .Shapes(i).ControlFormat.Value = .Shapes(32).ControlFormat.Value
    Next i
    End With
    End Sub
    [/VBA]

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by mae0429
    Problem here is that, apparently, when using control toolbox checkboxes on an embedded chart, they are part of the Shapes collection.
    And where did you mention an embedded chart?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Regular
    Joined
    Jun 2008
    Posts
    64
    Location
    From my first post:

    Quote Originally Posted by mae0429
    I've got an embedded chart on a worksheet and it has 24 checkboxes (control toolbox, not form) corresponding to different devices.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •