Change Font color in a cell based on Option button selection

BOWNER

New Member
Joined
Mar 9, 2015
Messages
6
Hi Gurus,

I am new to excel VBA and I am loving it :) I request your help ladies and gentlemen.

I am trying to change the font color in a cell based on the option button selection. The option button is an Active X control.

for example: If The option button is selected, then the value in a cell should be back in color, if the option button is not selected, then the font color in the cell should be white.

This is an active X option button and I cannot reference it to cells.

This is what I have so far:

Private Sub Work_change (ByVal FontChange As Boolean)
If FontChange.Address = OptionButtion.value Then
If FontChange.Value = True Then Range("A1").Font.Color = vbBlack
If FontChange.Value = False Then Range("A1").Font.Color = vbWhite
End If
End Sub

Please help gurus
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,761
Office Version
2013
Platform
Windows
Try
Code:
Private Sub CommandButton1_Click() ' change button name to suit
If Range("A1").Font.Color = vbBlack Then
Range("A1").Font.Color = vbWhite
Exit Sub
Else:
If Range("A1").Font.Color = vbWhite Then Range("A1").Font.Color = vbBlack
End If
End Sub
 

BOWNER

New Member
Joined
Mar 9, 2015
Messages
6
Thank michael, but I have an option button (radio button) and I need help with that....
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,761
Office Version
2013
Platform
Windows
Use 2 buttons, option buttons are not generally designed to be On / Off as a single entity
Code:
Private Sub optionButton1_Click()
If OptionButton1.Value = True Then Range("A1").Font.Color = vbWhite
End Sub
Private Sub optionButton2_Click()
If OptionButton2.Value = True Then Range("A1").Font.Color = vbBlack
End Sub
 

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
18,761
Office Version
2013
Platform
Windows
Are they activeX buttons ??
 

BOWNER

New Member
Joined
Mar 9, 2015
Messages
6
I got the code to work....it changes teh font color when the option button is selected, BUT does not change it back to the original color when the option button is deselected..

Sub optionButton1_Click()
With Range("A1")
If optionButton1.Value Then
.Font.Color = vbRed
Else
.Font.Color = vbBlack
End If
End With
End Sub
 

BOWNER

New Member
Joined
Mar 9, 2015
Messages
6
I got it to work, thank Michael :) you are correct, I need two option buttons.
 

Watch MrExcel Video

Forum statistics

Threads
1,095,544
Messages
5,445,099
Members
405,316
Latest member
joaoamaro

This Week's Hot Topics

Top