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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,222,123
Messages
6,164,086
Members
451,872
Latest member
TimothyLynn

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