Option Button code not working

S

Sara

I am trying to use this code to hide/unhide text and background color. For
some reason it is not working. I want to have two option buttons and if 1 is
not checked the font and background should disappear. It's not happening when
I click on Option Button 2?

Private Sub OptionButton1_Click()

If OptionButton1.Value = True Then
Me.Range("Y27:AA27").Font.Color = RGB(0, 0, 0)
Else
Me.Range("Y27:AA27").Font.Color = RGB(255, 255, 255)
End If

End Sub
 
M

Mike H

Sara,

You need to put it in the change event because it can never become FALSE by
clicking it. Try this variation

Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
Range("Y27:AA27").Font.ColorIndex = 2
Else
Range("Y27:AA27").Font.ColorIndex = 0
End If
End Sub

Mike
 
B

Bob Phillips

That vent won't kick in if the second is clicked, so you need similar code
in its click event.
 
S

Sara

Thank you so much Mike. That worked.

Mike H said:
Sara,

You need to put it in the change event because it can never become FALSE by
clicking it. Try this variation

Private Sub OptionButton1_Change()
If OptionButton1.Value = True Then
Range("Y27:AA27").Font.ColorIndex = 2
Else
Range("Y27:AA27").Font.ColorIndex = 0
End If
End Sub

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top