CheckBox question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have many, many, many check boxes on a worksheet. Under certain conditions
when the sheet is activated, I need to uncheck ALL the checkboxes. Without
naming each checkbox individually How can I do this in a loop?

thanks
 
Try this

Dim CB As OLEObject

For Each CB In ActiveSheet.OLEObjects
If TypeName(CB) = "CheckBox" Then
CB.Object.Value = False
End If
Next CB
 
Dave Peterson posted this

And if you used checkboxes from the Forms toolbar (on a worksheet):
ActiveSheet.CheckBoxes.Value = xlOn 'xlOff
 
Ok, which toolbar did you use to create the checkbox ?
 
Ok, I missed one thing in the previous code. This should work ok:

Sub Uncheck()
Dim CB As OLEObject

With Sheets("Sheet1")
For Each CB In .OLEObjects
If TypeName(CB.Object) = "CheckBox" Then
CB.Object.Value = False
End If
Next CB
End With
End Sub
 
Sir,

Can the same code be used if the checkboxes are on a userform?

Can similiar code be used for optionbuttons?

Thank you

dtn
 
'-----------------------------------------------------------------
Private Sub ClearCheckboxes()
'-----------------------------------------------------------------
Dim ctl As msforms.Control

For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl

End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top