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
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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
 
Upvote 0
Thank michael, but I have an option button (radio button) and I need help with that....
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,212,933
Messages
6,110,756
Members
448,295
Latest member
Uzair Tahir Khan

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