Clear all checkboxes with simple code

Drmwvr7266

Board Regular
Joined
Apr 7, 2002
Messages
164
Is there a way to set all checkboxes back to false (unchecked) without writing a great deal of code? I have 37 checkboxes and just want to write some code that will reset them when I clicked my commandbutton1.

Thanx in advance.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
If your checkboxes have a name like CheckBox1, CheckBox2, etc, you can use a For like this

For i = 1 to 37
Me.Controls("CheckBox" & i).Object = False
Next i
 

Drmwvr7266

Board Regular
Joined
Apr 7, 2002
Messages
164
I have the code as such:

Private Sub CommandButton1_Click()

For i = 1 To 37
Me.Controls("CheckBox" & i).Object = False
Next i

End Sub


Why am I getting an error at Controls? Should I mention that the checkboxes are on a SHEET, not a userform? The commandbutton is also on the sheet.
 

Mudface

MrExcel MVP
Joined
Feb 18, 2002
Messages
3,339
This should work OK: -

Code:
Private Sub CommandButton1_Click()

For Each ctl In ActiveSheet.OLEObjects
    If ctl.ProgId = "Forms.CheckBox.1" Then
        ctl.Object.Value = False
    End If
Next ctl

End Sub

Also see http://www.mrexcel.com/board/viewtopic.php?topic=19306&forum=2

Edit: - forgot to add- original code was from Damon Ostrander in the post above.
This message was edited by Mudface on 2002-09-05 12:28
 

Drmwvr7266

Board Regular
Joined
Apr 7, 2002
Messages
164
Thank you Mudface. As always, the gang here at Mr. Excel pull through for me.
 

Forum statistics

Threads
1,143,710
Messages
5,720,395
Members
422,283
Latest member
Parvathy

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
Top