Excel VBA Font Color

To change the font color, first, we need to identify what cells we are going to change.

Range (“A1:A10”)

Then we need to select the FONT property.

Range (“A1:A10”).Font

Then what do we want to do with this font? So, select color.

Range (“A1:A10”).Font.Color

Like this, we need to construct the code to change the font color. It does not look easy.

But remember, everything seems tough at the beginning. Later you will get the hang of it.

You are free to use this image on you website, templates, etc., Please provide us with an attribution linkHow to Provide Attribution?Article Link to be HyperlinkedFor eg:Source: VBA Font Color (wallstreetmojo.com)

How to Change Font Color using VBA?

Example #1 – Using Color Index

The Color Index property is different from the Color property in VBAColor Property In VBAVBA Colour Index is used to change the colours of cells or cell ranges. This function has unique identification for different types of colours.read more. Using numerical values, we can change the color of cells and fonts.

Numbers range from 1 to 56, and each number represents different colors. Below is the list of numbers and their colors.

Let us test this out.

We have a value in cell A1.

We want to change the color of the cell A1 font to green. Below is the code.

Code:

Sub FontColor_Example1()

Range(“A1”).Font.ColorIndex = 10

End Sub

It will change the color of the cell A1 font to green.

We can also use the CELLS property to change the color of the font.

Sub FontColor_Example1()

Cells(1, 1).Font.ColorIndex = 10

End Sub

Like this, we can use numbers 1 to 56 to apply the desired color to the font.

Example #2 – Using Color Property

Color Index has very limited colors from 1 to 56, but using the COLOR property, we can use 8 built-in colors:  vbBlack, vbRed, vbGreen, vbBlue, vbYellow, vbMagenta, vbCyan, vbWhite.

For these colors, we do not need to supply any numbers. Rather, we can access them using their name, as shown above. Below is the example code for all 8 colors.

Sub vbBlack_Example()

Range(“A1”).Font.Color = vbBlack

End Sub

Sub vbRed_Example()

Range(“A1”).Font.Color = vbRed

End Sub

Sub vbGreen_Example()

Range(“A1”).Font.Color = vbGreen

End Sub

Sub vbBlue_Example()

Range(“A1”).Font.Color = vbBlue

End Sub

Sub vbYellow_Example()

Range(“A1”).Font.Color = vbYellow

End Sub

Sub vbMagenta_Example()

Range(“A1”).Font.Color = vbMagenta

End Sub

Sub vbCyan_Example()

Range(“A1”).Font.Color = vbCyan

End Sub

Sub vbWhite_Example()

Range(“A1”).Font.Color = vbWhite

End Sub

Example #3 – Using Color Property with RGB Function

We have seen that we have only 8 built-in colors to work with. But we need to use the RGB function to have various colors. Besides built-in colors, we can create our colors by using the VBA VBA RGBVBA RGBRGB can be also termed as red green and blue, this function is used to get the numerical value of the color value, this function has three components as a named range and they are red, blue and green the other colors are considered as the components of these three different colors in VBA.read more function.

Look at the syntax of the RGB function.

RGB (Red, Green, Blue)

RGB stands for “Red, Green, and Blue.” Therefore, we need to supply numbers from 0 to 255 for each color to construct colors.

Below are a few examples for you.

Below are some of the macro code examples

Sub RGB_Example()

Range(“A1”).Font.Color = RGB(0, 0, 0) ‘Change the font colour to black End Sub

Sub RGB_Example()

Range(“A1”).Font.Color = RGB(16, 185, 199) ‘Font color will be this End Sub

Sub RGB_Example()

Range(“A1”).Font.Color = RGB(106, 15, 19) ‘Font color will be this End Sub

Sub RGB_Example()

Range(“A1”).Font.Color = RGB(216, 55, 19) ‘Font color will be this End Sub

This article has been a guide to VBA Font Color. Here, we learn how to change the font color by using the VBA color index, color property with RGB function along with examples, and download an Excel template. Below are some useful Excel articles related to VBA: –

  • VBA ExamplesVBA ChDirAlternate Row Color in Excel