Uncheck every Check Box Q

S

Sean

Would there be a reason why the code below will not uncheck a Checkbox
that is "True" or ticked?


Sub UncheckBoxes()

Dim cb As CheckBox
Application.ScreenUpdating = False

Sheets("Input").Select
For Each cb In ActiveSheet.CheckBoxes
cb.Value = False
Next cb

End Sub
 
B

Bob Phillips

It works if the checkboxes are from the Forms toolbar, but not Control
Toolbox checkboxes.

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
D

Dave Peterson

Did you assign a linked cell to those checkboxes?
Did you lock those linked cells?
Did you protect the worksheet that contained those linked cells?

ps. You could drop the .select and just use:

For Each cb In sheets("Input").CheckBoxes
 
S

Sean

Thanks Dave, took what Bob said and sourced this piece of code that
runs

Sub DelAllCheckBoxes()
Dim shp As Shape

Application.ScreenUpdating = False

Sheets("Sheet1").Activate
On Error Resume Next
For Each shp In ActiveSheet.Shapes
If shp.FormControlType = xlCheckBox Then
shp.Delete
End If
Next shp
On Error GoTo 0
End Sub
 
D

Dave Peterson

That doesn't look like you're unchecking checkboxes.

But glad you have what you want.
 
S

Sean

Now you have me worried Dave, it does uncheck what I have, but maybe
there are instances when it won't work. I have taken my CheckBox from
the control toolbar
 
S

Sean

Your totally correct Dave, I copied the wrong code to the NG, this is
what I should have shown Doh!

Sub UncheckBoxes()
Application.ScreenUpdating = False

Sheets("Input").Activate
For Each ctrl In ActiveSheet.OLEObjects
If UCase(TypeName(ctrl.Object)) = "CHECKBOX" Then
If ctrl.Object.Value = True Then
ctrl.Object.Value = False
End If
End If
Next
End Sub
 
D

Dave Peterson

That looks better <vbg>.

Here's another way:

Option Explicit
Sub Uncheckboxes2()
Dim wks As Worksheet
Dim OLEObj As OLEObject

Set wks = Worksheets("Input")

For Each OLEObj In wks.OLEObjects
If TypeOf OLEObj.Object Is MSForms.CheckBox Then
OLEObj.Object.Value = False
End If
Next OLEObj
End Sub
 

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

Top