PC Review


Reply
Thread Tools Rate Thread

Changing Option Buttons status

 
 
Fan924
Guest
Posts: n/a
 
      9th Jul 2009
I have 3 Option Buttons on a sheet. Can I set the true/false status of
the buttons using a macro from another sheet?
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      9th Jul 2009

If you know the names of the optionbuttons (from the Control toolbox toolbar,
right?):

With Worksheets("othersheetnamehere")
.OptionButton1.Value = False
.OptionButton2.Value = False
.OptionButton3.Value = False
End With

If the optionbuttons are from the Forms toolbar:

With Worksheets("othersheetnamehere")
.OptionButtons("Option Button 1").Value = xlOff
.OptionButtons("Option Button 2").Value = xlOff
.OptionButtons("Option Button 3").Value = xlOff
End With

Fan924 wrote:
>
> I have 3 Option Buttons on a sheet. Can I set the true/false status of
> the buttons using a macro from another sheet?


--

Dave Peterson
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      12th Jul 2009
Assuming we are talking about ALL the OptionButtons on a worksheet, these
can also be reset without know the individual names...

Sub ResetFormsOptionButtons()
Worksheets("Sheet1").OptionButtons.Value = False
End Sub

Sub ResetActiveXOptionButtons()
Dim OptBtn As OLEObject
For Each OptBtn In Worksheets("Sheet1").OLEObjects
OptBtn.Object.Value = False
Next
End Sub

--
Rick (MVP - Excel)


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If you know the names of the optionbuttons (from the Control toolbox
> toolbar,
> right?):
>
> With Worksheets("othersheetnamehere")
> .OptionButton1.Value = False
> .OptionButton2.Value = False
> .OptionButton3.Value = False
> End With
>
> If the optionbuttons are from the Forms toolbar:
>
> With Worksheets("othersheetnamehere")
> .OptionButtons("Option Button 1").Value = xlOff
> .OptionButtons("Option Button 2").Value = xlOff
> .OptionButtons("Option Button 3").Value = xlOff
> End With
>
> Fan924 wrote:
>>
>> I have 3 Option Buttons on a sheet. Can I set the true/false status of
>> the buttons using a macro from another sheet?

>
> --
>
> Dave Peterson


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      12th Jul 2009
I think I'd be more careful with the second one--there may be other OLEObjects
on that sheet:


Sub ResetActiveXOptionButtons()
Dim OptBtn As OLEObject
For Each OptBtn In Worksheets("Sheet1").OLEObjects
If TypeOf OptBtn.Object Is MSForms.OptionButton Then
OptBtn.Object.Value = False
End If
Next OptBtn
End Sub

And I've seen where lots and lots (much more than the OP's 3) of optionbuttons
(from the forms toolbar) would cause that first routine to break. Looping
through all of them would work, though:

Dim OptBtn As OptionButton
For Each OptBtn In Worksheets("Sheet1").OptionButtons
OptBtn.Value = xlOff
Next OptBtn



Rick Rothstein wrote:
>
> Assuming we are talking about ALL the OptionButtons on a worksheet, these
> can also be reset without know the individual names...
>
> Sub ResetFormsOptionButtons()
> Worksheets("Sheet1").OptionButtons.Value = False
> End Sub
>
> Sub ResetActiveXOptionButtons()
> Dim OptBtn As OLEObject
> For Each OptBtn In Worksheets("Sheet1").OLEObjects
> OptBtn.Object.Value = False
> Next
> End Sub
>
> --
> Rick (MVP - Excel)
>
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > If you know the names of the optionbuttons (from the Control toolbox
> > toolbar,
> > right?):
> >
> > With Worksheets("othersheetnamehere")
> > .OptionButton1.Value = False
> > .OptionButton2.Value = False
> > .OptionButton3.Value = False
> > End With
> >
> > If the optionbuttons are from the Forms toolbar:
> >
> > With Worksheets("othersheetnamehere")
> > .OptionButtons("Option Button 1").Value = xlOff
> > .OptionButtons("Option Button 2").Value = xlOff
> > .OptionButtons("Option Button 3").Value = xlOff
> > End With
> >
> > Fan924 wrote:
> >>
> >> I have 3 Option Buttons on a sheet. Can I set the true/false status of
> >> the buttons using a macro from another sheet?

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      12th Jul 2009
>I think I'd be more careful with the second one--there may be other
>OLEObjects
> on that sheet:
>
> Sub ResetActiveXOptionButtons()
> Dim OptBtn As OLEObject
> For Each OptBtn In Worksheets("Sheet1").OLEObjects
> If TypeOf OptBtn.Object Is MSForms.OptionButton Then
> OptBtn.Object.Value = False
> End If
> Next OptBtn
> End Sub


Yeah, I forgot to put the TypeOf check in (again<g>). Thanks for noticing
that.


> And I've seen where lots and lots (much more than the OP's 3) of
> optionbuttons
> (from the forms toolbar) would cause that first routine to break. Looping
> through all of them would work, though:
>
> Dim OptBtn As OptionButton
> For Each OptBtn In Worksheets("Sheet1").OptionButtons
> OptBtn.Value = xlOff
> Next OptBtn


I did qualify my posting by saying "Assuming we are talking about ALL the
OptionButtons on a worksheet" as it was hard to tell from the OP's posting
what was on the sheet.


--
Rick (MVP - Excel)

 
Reply With Quote
 
Fan924
Guest
Posts: n/a
 
      15th Jul 2009
> * * With Worksheets("othersheetnamehere")
> * * * * .OptionButton1.Value = False
> * * * * .OptionButton2.Value = False
> * * * * .OptionButton3.Value = False
> * * End With


Thanks Dave
 
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
Retrieving Information from Option Group (Option Buttons) Pam Microsoft Access Queries 3 10th Nov 2008 03:53 AM
Binding Values from a Table to Option Buttons contained in an Option Group faerewing@gmail.com Microsoft Access 3 15th Jan 2007 10:01 PM
Changing text size in option buttons on a userform =?Utf-8?B?Q29lbiBCdXJnZXI=?= Microsoft Excel Programming 1 7th Aug 2005 09:04 AM
RE: Navigating between option buttons is not selecting the option =?Utf-8?B?ZHJoYWx0ZXI=?= Microsoft Excel Programming 1 3rd Jun 2005 02:28 PM
RE: Navigating between option buttons is not selecting the option =?Utf-8?B?R2l4eGVyX0pfOTc=?= Microsoft Excel Programming 4 2nd Jun 2005 02:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:03 AM.