Change Option Button text color after selected

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
224
Office Version
  1. 365
Platform
  1. Windows
I have a model with several Option Button groups (Active X, not Form Controls).
Is there a way to change the color of the text of the selected button? This would clearly show the user what he/she had selected.
Many thanks,
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Rhere a number of otions on this previous thread for toggling Button colors. If they aren't useful please post back
 
Upvote 0
Thank you Michael and Abdel,

I used one code which worked well for ForeColor, but when I toggle the option, and the value is False, I tried the following to change it back to standard, but it does not and stays red:

Private Sub OptionButton2_Click()
If OptionButton2.Value = True Then OptionButton2.ForeColor = vbRed
If OptionButton2.Value = False Then OptionButton2.ForeColor = vbBlack
End Sub
 
Upvote 0
Try using the controls Change Event & see if that solves your issue

VBA Code:
Private Sub OptionButton2_Change()
     With Me.OptionButton2
        .ForeColor = IIf(.Value, vbRed, vbButtonText)
    End With
End Sub

Dave
 
Upvote 0
Solution
@dmt32 what if have many option buttons like green for oprionbutton1 and red for optionbutton2 and blue for optionbutton 3
how is your code ?
 
Upvote 0
I was responding to the OP & their post but you could adapt my suggestion to a common code & pass the required colour value to it.

Dave
 
Upvote 0
Hi Dave, Your little piece if code works perfectly!

Many thanks to all,

Arie
 
Upvote 0

Forum statistics

Threads
1,214,403
Messages
6,119,309
Members
448,886
Latest member
GBCTeacher

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