VB codes for option buttons

G

Guest

hi,
I have a command button and two option buttons in my file and I need switch
between two option buttons(I mean selecting button1 or button2 alternatively)
by pressing the command box by means of VB codes.can anybody help me.
thanks
 
G

Guest

Did you try my suggestion from yesterday of making sure that the option
buttons (from the control toolbox) are in the same group making the buttons
mutually exclusive (selecting one deselects the other). Or did you intend
something else.
 
G

Guest

yes Jim,I sent you the reply.the group names are correct, but I don't want it
manually.what I need is macro do it for me.many thanks
 
G

Guest

So if I understand you correctly you have 2 option buttons adna command
button. You wnat the command button to toggle the option buttons... If so then

Private Sub CommandButton1_Click()
With Sheet1
If .OptionButton1.Value = True Then
.OptionButton2.Value = True
Else
.OptionButton1.Value = True
End If
End With
End Sub
 
G

Guest

YOU ARE GREAT JIM THANK YOU SO MUCH!!!

Jim Thomlinson said:
So if I understand you correctly you have 2 option buttons adna command
button. You wnat the command button to toggle the option buttons... If so then

Private Sub CommandButton1_Click()
With Sheet1
If .OptionButton1.Value = True Then
.OptionButton2.Value = True
Else
.OptionButton1.Value = True
End If
End With
End Sub
 
G

Guest

Jim, what is the equivalent form_load in visual basic in VBA.you know what, I
want if the file is opened up, the 2 optin bottuns are not selected.in VB we
can have:
sub private form_load ()
optionbutton1.value=false
optionbutton1.value=false
or something like that.
any comment??
 
G

Guest

You can view an objects events by selecting the object in the (general) drop
down above the code window. When you make the selection the Declarations will
be populated in the drop down just to the right. So for example in the VBE
select sheet 1 which has the command buttons and option buttons embedded in
it. The General drop down will list the worksheet and all of the controls. By
selecting the sheet or the control you will get the event declarations in the
next drop down. Now just choose the event you want and a code stub will be
inserted.

You will also want to look at the Workbook objects stored in ThisWorkBook.
for more info check out Chip Pearson's web site at...

http://www.cpearson.com/excel/topic.aspx
 
G

Guest

I really appreciate it Jim.

Jim Thomlinson said:
You can view an objects events by selecting the object in the (general) drop
down above the code window. When you make the selection the Declarations will
be populated in the drop down just to the right. So for example in the VBE
select sheet 1 which has the command buttons and option buttons embedded in
it. The General drop down will list the worksheet and all of the controls. By
selecting the sheet or the control you will get the event declarations in the
next drop down. Now just choose the event you want and a code stub will be
inserted.

You will also want to look at the Workbook objects stored in ThisWorkBook.
for more info check out Chip Pearson's web site at...

http://www.cpearson.com/excel/topic.aspx
 

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