VBA Font Color

Excel VBA Font Color

VBA Font Color property is used to change the font color of excel cells using vba code. We can change the color of the font in multiple ways using color index, color property with RGB function.

When I prepare a dashboard in excelPrepare A Dashboard In ExcelThe Excel Dashboard is an enhanced form of data visualization that helps managers plan and achieve business targets and facilitates decision-making. Users can apply excel table and charts, pivot table and charts, interactive controls, excel formulas, etc., to create excel dashboards.read more, I usually spend a considerable amount of time formatting cells, fonts, etc. Often I feel like an excel beautician by looking at the various colors of the excel formatting. Changing the font color in excel worksheet is an easy job, but when it comes to Excel, you should know the ways of writing VBA codeWriting VBA CodeVBA code refers to a set of instructions written by the user in the Visual Basic Applications programming language on a Visual Basic Editor (VBE) to perform a specific task.read more to change the font color.

To change the font color, first, we need to identify what are the 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 looks difficult, isn’t it?

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

VBA Font Color

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

How to Change Font Color using VBA?

You can download this VBA Font Color Excel Template here – VBA Font Color Excel Template

Example #1 – Using Color Index

Color Index property is different from the Color property in VBA. By using numerical values, we can change the color of cells, fonts.

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

VBA Font Color Example 1

Ok, lets test this out.

I have a value in cell A1.

VBA Font Color Example 1-1

I 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

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

VBA FontColor Example 1-2

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

Code:

Sub FontColor_Example1()

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

End Sub

Like this, we can use numbers from 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 by using COLOR property, we can use 8 built-in colors vbBlack, vbRed, vbGreen, vbBlue, vbYellow, vbMagenta, vbCyan, vbWhite.

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

Code:

Sub vbBlack_Example()

  Range("A1").Font.Color = vbBlack

End Sub

Code:

Sub vbRed_Example()

  Range("A1").Font.Color = vbRed

End Sub

Code:

Sub vbGreen_Example()

  Range("A1").Font.Color = vbGreen

End Sub

Code:

Sub vbBlue_Example()

  Range("A1").Font.Color = vbBlue

End Sub

Code:

Sub vbYellow_Example()

  Range("A1").Font.Color = vbYellow

End Sub

Code:

Sub vbMagenta_Example()

  Range("A1").Font.Color = vbMagenta

End Sub

Code:

Sub vbCyan_Example()

  Range("A1").Font.Color = vbCyan

End Sub

Code:

Sub vbWhite_Example()

  Range("A1").Font.Color = vbWhite

End Sub

Example #3 – Using Color Property with RGB Function

As we have seen, we have only 8 built-in colors to work with. But to have a wide variety of colors, we need to use the function called RGB. Apart from built-in colors, we can create our own colors by using VBA RGBVBA RGBThe RGB function is used to obtain the numerical value of a colour value. This function contains three named range components: red, blue, and green. Other colours are considered components of these three different colours in VBA.read more function.

Look at the syntax of the RGB function.

RGB (Red, Green, Blue)

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

Below are a few examples for you.

VBA FontColor Example 3

Below are some of the macro code examples

Code:

Sub RGB_Example()

  Range("A1").Font.Color = RGB(0, 0, 0)
  'Change the font colour to black
End Sub

Code:

Sub RGB_Example()

  Range("A1").Font.Color = RGB(16, 185, 199)
  'Font color will be this
End Sub

Code:

Sub RGB_Example()

  Range("A1").Font.Color = RGB(106, 15, 19)
  'Font color will be this
End Sub

Code:

Sub RGB_Example()

  Range("A1").Font.Color = RGB(216, 55, 19)
  'Font color will be this
End Sub

Recommended Articles

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

  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>