Change Font color in a cell based on Option button selection

Thanks Thanks:  0
Likes Likes:  0
Results 1 to 10 of 10

Thread: Change Font color in a cell based on Option button selection

  1. #1
    New Member
    Join Date
    Mar 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Change Font color in a cell based on Option button selection

     
    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

  2. #2
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    Western NSW
    Posts
    15,557
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    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
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  3. #3
    New Member
    Join Date
    Mar 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    Thank michael, but I have an option button (radio button) and I need help with that....

  4. #4
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    Western NSW
    Posts
    15,557
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    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
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  5. #5
    New Member
    Join Date
    Mar 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    Nope not working

  6. #6
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    Western NSW
    Posts
    15,557
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    Are they activeX buttons ??
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  7. #7
    New Member
    Join Date
    Mar 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    Quote Originally Posted by Michael M View Post
    Are they activeX buttons ??
    yes they are....

  8. #8
    Board Regular Michael M's Avatar
    Join Date
    Oct 2005
    Location
    Western NSW
    Posts
    15,557
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    maybe you should read here then...

    Office Update breaks ActiveX controls | Excel Matters
    Regards
    Michael M
    ---------------------------------------
    The more I learn, the less I seem to know.....A Please and Thank You cost nothing !
    It's easier to debug if we can see the whole macro !
    Home 2007 & 2013

    - Posting guidelines, forum rules and terms of use

    - To download Mr Excel HTML Maker

    - Try searching for your answer first, see how

    - Read the FAQs

    - List of BB codes


    [CODE]Place Your Code Here[/CODE]

  9. #9
    New Member
    Join Date
    Mar 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

    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

  10. #10
    New Member
    Join Date
    Mar 2015
    Posts
    6
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Change Font color in a cell based on Option button selection

      
    I got it to work, thank Michael you are correct, I need two option buttons.

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com