Checking and Unchecking CheckBoxes using code

A

Ayo

I have 7 checkbox and 2 option buttons. One of the option buttons unchecks
all the checkboxes and the other one checks all the options buttons. In Excel
2003 I was able to use somthing like this to do that:
For Each ctl In InputForm2.Controls
If TypeName(ctl) = "CheckBox" Then
If ctl.Value = True Then
ctl.Value = False
ElseIf ctl.Value = False Then
ctl.Value = True
End If
End If
Next ctl

This don't work in Excel 2007. Any ideas
Thanks
 
R

Ron de Bruin

I have no problem running this in a test userform
Do you get a error?

Private Sub CommandButton1_Click()
Dim ctl As Control
For Each ctl In Me.Controls
If TypeName(ctl) = "CheckBox" Then
ctl.Value = Not ctl.Value
End If
Next ctl
End Sub
 
A

Ayo

I'm sorry, I should have mentioned I was trying to run this in Excel 2007.
This works fine in 2003, which is where the code snippet came from. I was
looking for something like that for 2007.
Is there any?
 

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