ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel VBA Problem - Clearing multiple checkboxes (https://www.excelbanter.com/excel-programming/298733-excel-vba-problem-clearing-multiple-checkboxes.html)

rott[_7_]

Excel VBA Problem - Clearing multiple checkboxes
 
Hi I have an excel spreadsheet that has 156 checkboxes on it. What I a
trying to do is with the click of a command button, I want to be abl
to clear all check boxes at once.

I know there is an easier way than going through all 156 checkboxes an
setting their value to false.

Eg. CheckBox1.Value = False
CheckBox2.Value = False

Can this be done in a For statement or something simple that wil
execute when the command button is pressed and clear all th
checkboxes.

I have tried doing something like this but it does not work:

Private Sub Cmd1_Click()
Dim i As Integer

For i = 1 To 156 Step 1
Checkbox(i).Value = False
Next i

End Sub

Can someone help me out?
Thank

--
Message posted from http://www.ExcelForum.com


Jake Marx[_3_]

Excel VBA Problem - Clearing multiple checkboxes
 
Hi rott ,

Something like this should do the trick:

Sub ClearChkBoxes()
Dim ctl As OLEObject

For Each ctl In Worksheets("Sheet1").OLEObjects
If TypeOf ctl.Object Is MSForms.CheckBox Then
ctl.Object.Value = False
End If
Next ctl
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Hi I have an excel spreadsheet that has 156 checkboxes on it. What I
am trying to do is with the click of a command button, I want to be
able to clear all check boxes at once.

I know there is an easier way than going through all 156 checkboxes
and setting their value to false.

Eg. CheckBox1.Value = False
CheckBox2.Value = False

Can this be done in a For statement or something simple that will
execute when the command button is pressed and clear all the
checkboxes.

I have tried doing something like this but it does not work:

Private Sub Cmd1_Click()
Dim i As Integer

For i = 1 To 156 Step 1
Checkbox(i).Value = False
Next i

End Sub

Can someone help me out?
Thanks


---
Message posted from http://www.ExcelForum.com/


rott[_8_]

Excel VBA Problem - Clearing multiple checkboxes
 
Excellent thanks man that worked like a charm.

rot

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 01:32 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com