Change Option Button text color after selected

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
108
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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,118
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Rhere a number of otions on this previous thread for toggling Button colors. If they aren't useful please post back
 

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
108
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
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,508
Office Version
  1. 2019
Platform
  1. Windows

ADVERTISEMENT

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
 
Solution

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
994
Office Version
  1. 2010
@dmt32 what if have many option buttons like green for oprionbutton1 and red for optionbutton2 and blue for optionbutton 3
how is your code ?
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,508
Office Version
  1. 2019
Platform
  1. Windows

ADVERTISEMENT

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
 

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
108
Hi Dave, Your little piece if code works perfectly!

Many thanks to all,

Arie
 

Watch MrExcel Video

Forum statistics

Threads
1,129,388
Messages
5,636,032
Members
416,892
Latest member
Bensch

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
Top