"Highlight" a radio button's text.

sts023

Board Regular
Joined
Sep 1, 2008
Messages
106
Hi Guys!
This one should be easy, but I'm just going round in circles trying to fix a simple problem.
I have a Form, on which is a Frame within which are four radio buttons with their associated texts.
When the Form is Initialised, I'd like the second radio button to be set.
Using the following code (where optCreate is the name of the second radio button)
Code:
Private Sub UserForm_Initialize()
  Me.optCreate = True
End Sub
The second button is selected, but there is a border around the text of the first radio button!

I'd like the border to be around the second radio button, as it would be if I'd selected it "manually", so I tried the following code
Code:
Private Sub UserForm_Initialize()
  Me.optCreate = True
  Me.optCreate.SetFocus
End Sub

This has the curious effect (at least it's curious to me) of removing the border from all of the radio buttons.

How do I get the border around radio button 2 using VBA?

All help or hints gratefully received....
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I used this code and it does as you require. The border is around the 2nd option button and it is selected. I can only imagine some other code is causing the issue.
Code:
Private Sub UserForm_Initialize()
    OptionButton2.SetFocus
    OptionButton2.Value = True
End Sub
 
Upvote 0
the other way round...
Code:
Private Sub UserForm_Initialize()
  Me.optCreate.SetFocus
  Me.optCreate = True
End Sub
 
Upvote 0
I used this code and it does as you require. The border is around the 2nd option button and it is selected. I can only imagine some other code is causing the issue.
I did not test your code, but simply tested what I would have written - which does exactly what you want
I have now (belatedly :oops: ) tested your original code - which also does exactly what you want :eeek:

So @gallen is probably correct :)
 
Upvote 0
On noticing that executing "manual" VBA (i.e. running a Sub to just show the Userform), Excel "remembers" the previously selected radio button.

I've now slightly modified my code, calling it from both Initialise and Activate, and including the Repaint command.

I don't know why it now works, and it hasn't (yet) caused any loss of data from communication with the User, so I include my new code which may be helpful to any other poor soul with a similar problem.

I'm sure the wiser minds at MrExcel will point out any possible dire consequences...:confused:

Code:
Private Sub UserForm_Activate()
  Call SetInitialOpt
End Sub
Private Sub UserForm_Initialize()
  Call SetInitialOpt
End Sub
Public Sub SetInitialOpt()
  Me.Repaint
  Me.optCreate.SetFocus
  Me.optCreate = True
End Sub 'SetInitialOpt
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top