VBA font color change ?

audrey

Active Member
Joined
Jul 30, 2008
Messages
491
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!
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
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:
Upvote 0
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
 
Upvote 0
Thank you both! small question....

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


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
 
Upvote 0
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.
 
Upvote 0
Hi. Do you know the format for specifying a font color by RGB values in the regular Format Cells editor in excel? I tried [RGB(175,11,28)] and it did not work.

Thanks!

----------------------------------------------------

Goodmorning,

I have been able to make these work in my situation.

in MY IF/ THEN statements:

If I wanted to use the ColorINdex format in excel by using the color index chart I use this:

Code:
Range("C12").Font.ColorIndex = 3

but If I wanted to use the RGB color numbering system its not color index it's just color:

Code:
Range("C12").Font.Color = RGB(100, 255, 100)

This has worked for me in my situation.

I also used this great website for help.



https://msdn.microsoft.com/en-us/library/cc296089(v=office.12).aspx


goodluck.
 
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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