PC Review


Reply
Thread Tools Rate Thread

Checking and Unchecking CheckBoxes using code

 
 
Ayo
Guest
Posts: n/a
 
      3rd Apr 2009
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
 
Reply With Quote
 
 
 
 
Ron de Bruin
Guest
Posts: n/a
 
      3rd Apr 2009
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


--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Ayo" <(E-Mail Removed)> wrote in message news:7986E7FB-77C1-4801-8610-(E-Mail Removed)...
>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

 
Reply With Quote
 
Ayo
Guest
Posts: n/a
 
      4th Apr 2009
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?

"Ron de Bruin" wrote:

> 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
>
>
> --
>
> Regards Ron de Bruin
> http://www.rondebruin.nl/tips.htm
>
>
>
>
> "Ayo" <(E-Mail Removed)> wrote in message news:7986E7FB-77C1-4801-8610-(E-Mail Removed)...
> >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

>

 
Reply With Quote
 
Ron de Bruin
Guest
Posts: n/a
 
      4th Apr 2009
I test it in 2007

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Ayo" <(E-Mail Removed)> wrote in message news:F029D5F5-D8C5-4396-8736-(E-Mail Removed)...
> 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?
>
> "Ron de Bruin" wrote:
>
>> 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
>>
>>
>> --
>>
>> Regards Ron de Bruin
>> http://www.rondebruin.nl/tips.htm
>>
>>
>>
>>
>> "Ayo" <(E-Mail Removed)> wrote in message news:7986E7FB-77C1-4801-8610-(E-Mail Removed)...
>> >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

>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking/unchecking all checkboxes in the one column of the gridview schapopa Microsoft ASP .NET 3 19th May 2010 11:19 AM
Checking and Unchecking CheckBoxes in code Ayo Microsoft Excel Misc 0 3rd Apr 2009 08:41 PM
checkboxes unchecking in VB code =?Utf-8?B?QW1hdGV1cg==?= Microsoft Access 4 15th May 2007 08:11 PM
Unchecking all Forms checkboxes in entire sheet michaelberrier Microsoft Excel Programming 3 22nd Dec 2006 04:54 PM
What is the code for checking or unchecking a checkbox? Dave R. Microsoft Access Macros 2 17th Jun 2005 07:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:15 PM.