select all - VBA

mcarter973

Board Regular
Joined
Mar 24, 2002
Messages
83
I have 8 check boxes - I would like to add a "select all" check box that would check all 8 boxes. Any help w/ code to get me started would be appreciated.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try this:

Private Sub CheckBox9_Click()
If CheckBox9.Value = True Then
CheckBox1.Value = True
CheckBox2.Value = True
...
CheckBox8.Value = True
Else
CheckBox1.Value = False
CheckBox2.Value = False
...
CheckBox8.Value = False
End If
End Sub
 
Upvote 0
Try this,

Private Sub Checkbox_Click()

Dim i
For i = 1 To 8
CB = "CheckBox" & i
Me.Controls(CB).Object.Value = True
Next i

End Sub

Just name your Checkboxes Checkbox1, Checkbox2, etc. Or anything numbered 1-8 at the end.

HTH
Corticus
This message was edited by corticus on 2002-08-15 05:55
 
Upvote 0
Or yet another suggestion where my "Select All" checkbox was named "CheckBox4":

<pre>
Private Sub CheckBox4_Change()
Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is msforms.CheckBox Then
ctrl.Value = Me.CheckBox4.Value
End If
Next
End Sub</pre>

HTH
 
Upvote 0
Mark- just out of interest, how would you do the same thing for a worksheet with a few checkboxes on it? I'd have thought you would iterate through the OleObjects collection, but I can't seem to make that work properly.
 
Upvote 0
Hey Mudface. This might help...<pre>
Private Sub Worksheet_Activate()
Dim tb As OLEObject
With ActiveSheet
For Each tb In .OLEObjects
If tb.OLEType = 2 Then
.OLEObjects(tb.Name).Object.Text = ""
End If
Next
End With
End Sub</pre>

I think this is better for what you are doing.<pre>
Private Sub Worksheet_Activate()
Dim cb As OLEObject
With ActiveSheet
For Each cb In .OLEObjects
If InStr(cb.ProgId, "CheckBox")<> 0 Then
.OLEObjects(cb.Name).Object.Value = False
End If
Next
End With
End Sub</pre>
Tom
This message was edited by TsTom on 2002-08-09 14:09
 
Upvote 0
Dammit, TsTom beat me to the punch :smile:, but here's how I would do it:

<pre>
Private Sub CheckBox5_Change()
Dim OLEctrl As OLEObject

For Each OLEctrl In OLEObjects
If OLEctrl.OLEType = 2 Then
OLEctrl.Object = CheckBox5.Object
End If
Next

End Sub</pre>
 
Upvote 0
It certainly does, I was using
Code:
Private Sub CheckBox3_Click()
Dim ctl As OLEObject

For Each ctl In ActiveSheet.OLEObjects
    If TypeName(ctl) = "CheckBox" Then ctl.Object.Value = CheckBox3.Value
Next ctl
    
End Sub
and derivatives of it but this mod of yours works nicely:-

Code:
Private Sub CheckBox3_Change()
Dim tb As OLEObject
With ActiveSheet
    For Each tb In .OLEObjects
        If tb.OLEType = 2 Then
            .OLEObjects(tb.Name).Object.Value = .OLEObjects("Checkbox3").Object.Value
        End If
    Next
End With

End Sub

Thanks, Tom, nice one :smile:.

Edit: Way too slow, Chris :smile:.
This message was edited by Mudface on 2002-08-09 14:10
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,331
Members
452,907
Latest member
Roland Deschain

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top