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

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
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
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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