Results 1 to 8 of 8

VBA font color change ?

This is a discussion on VBA font color change ? within the Excel Questions forums, part of the Question Forums category; Hello, with a checkbox button, I would like to have; - Font change color (from white to black, black to ...

  1. #1
    Board Regular
    Join Date
    Jul 2008
    Posts
    475

    Default VBA font color change ?

    Hello,
    with a checkbox button, I would like to have;

    - Font change color (from white to black, black to white)
    - Background change color (from white to black, black to white)

    is that possible ?

    It s not the whole sheet it should apply, lets say only A1:b3

    Thanks for your help!

  2. #2
    Board Regular
    Join Date
    May 2011
    Location
    London
    Posts
    1,564

    Default Re: VBA font color change ?

    Code:
    Sub TogCol()
    If ActiveSheet.CheckBox1.Value = True Then
        ActiveSheet.Range("a1:b3").Font.Color = vbBlack
    Else
        ActiveSheet.Range("a1:b3").Font.Color = vbWhite
    End If
    End Sub
    Code:
    Private Sub CheckBox1_Click()
    Call TogCol
    End Sub
    Right click on the control and go to view code
    Last edited by CharlesChuckieCharles; Apr 4th, 2012 at 12:13 PM.

  3. #3
    Board Regular
    Join Date
    Apr 2011
    Location
    Boca Raton, FL
    Posts
    836

    Default Re: VBA font color change ?

    is the checkbox a form control or activex or is it on a user form?

  4. #4
    Board Regular
    Join Date
    Jul 2008
    Posts
    475

    Default Re: VBA font color change ?

    Hi, it s an activex

    Quote Originally Posted by vaskov17 View Post
    is the checkbox a form control or activex or is it on a user form?

  5. #5
    Board Regular
    Join Date
    Apr 2011
    Location
    Boca Raton, FL
    Posts
    836

    Default Re: VBA font color change ?

    in that case Charles' solution should work but here is another option:

    Code:
    Sub CheckBox1_Click()
        With Range("A1:B3")
            If CheckBox1.Value Then
                .Font.Color = vbWhite
                .Interior.Color = vbBlack
            Else
                .Font.Color = vbBlack
                .Interior.Color = vbWhite
            End If
        End With
    End Sub

  6. #6
    Board Regular
    Join Date
    Jul 2008
    Posts
    475

    Default Re: VBA font color change ?

    Thank you both! small question....

    what if I want to use an RGB color ? what should I type in instead of vbWhite ?


    Quote Originally Posted by vaskov17 View Post
    in that case Charles' solution should work but here is another option:

    Code:
    Sub CheckBox1_Click()
        With Range("A1:B3")
            If CheckBox1.Value Then
                .Font.Color = vbWhite
                .Interior.Color = vbBlack
            Else
                .Font.Color = vbBlack
                .Interior.Color = vbWhite
            End If
        End With
    End Sub

  7. #7
    Board Regular
    Join Date
    May 2011
    Location
    London
    Posts
    1,564

    Default Re: VBA font color change ?

    vbwhite=RGB(255,255,255)
    vbblack = RGB(0,0,0)

    ActiveSheet.Range("a1:b3").Font.Color = RGB(0,0,0)

  8. #8
    Board Regular UMAKEMESIK's Avatar
    Join Date
    Oct 2005
    Posts
    256

    Default Re: VBA font color change ?

    Quote Originally Posted by CharlesChuckieCharles View Post
    vbwhite=RGB(255,255,255)
    vbblack = RGB(0,0,0)

    ActiveSheet.Range("a1:b3").Font.Color = RGB(0,0,0)

    Toall,

    Saw this code about using the checkboxes and if did work. But, what if I wanted to put a check box in cell a3 and only wanted cell d3s background to be red.

    then each cell the entire column of a would have a check box and if check its background would change color behind the check.

    I have three columns with check boxes

    columns D E and F.

    any help would be appreciated.

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