radio button text bold when clicked

D

dgold82

Is there a way to make the text of a radio button (option button from forms)
bold when clicked? Thanks.
 
J

Joel

Private Sub OptionButton1_Click()
Set but = ActiveSheet.OptionButton1
but.Font.Bold = True
End Sub
 
D

dgold82

Thanks for the reply but unfortunately I am getting an error saying variable
not defined and highlighting "but ="

I am running excel 2007 and placed your code in the worksheet module. I also
placed it in a regular module but got the same error.

Also, I want to make it so that any option button on the page turns its text
bold when clicked/filled not specific to to just one option button. I have
over 200 option buttons on each worksheet...

Thanks!
 
R

Rick Rothstein

That is because 'but' is not declared as some type of object. However, I
don't think the 'but' variable would even be needed. This is untested, but
try...

Private Sub OptionButton1_Click()
ActiveSheet.OptionButton1.Font.Bold = True
End Sub
 
D

dgold82

Got a runtime error...

Rick Rothstein said:
That is because 'but' is not declared as some type of object. However, I
don't think the 'but' variable would even be needed. This is untested, but
try...

Private Sub OptionButton1_Click()
ActiveSheet.OptionButton1.Font.Bold = True
End Sub
 
R

Rick Rothstein

I just re-read your original message and see you used an OptionButton from
the Form's toolbar... I'm pretty sure you can't change the font properties
on that type of control. Now, if you use an ActiveX OptionButton from the
Control Toolbox toolbar instead, then you can use this event code (it goes
on the worksheet's code window, *not* in a general Module) to make the font
bold whenever the OptionButton is selected...

Private Sub OptionButton1_Change()
With Sheet7.OptionButton1
.Font.Bold = .Value
End With
End Sub

Change the Sheet7 reference in my example code to the actual sheet name the
control is on.
 
G

Gary Keramidas

you can use the other's suggestions, but if you have more than 1 optionbutton,
you would need to set the font to normal if someone changes their mind or makes
a mistake.

just a thought.
 

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