EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home VBA VBA Resources VBA Tips VBA Font Color
 

VBA Font Color

Ashwani Jaiswal
Article byAshwani Jaiswal
Madhuri Thakur
Reviewed byMadhuri Thakur

Updated June 7, 2023

VBA Font Color

 

 

VBA Font Color

VBA has a lot of commands and functions to play with. We can do anything in VBA and apply that to Excel. Applying VBA in Excel is the easiest and most fun thing. VBA also has the function by which we can change the Color of cells and fonts and even bold the characters. VBA font color is used in different ways, and it helps to change the Color of the fonts in Excel.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

How to Color a Font Using VBA?

Let’s see the examples of font color in Excel VBA.

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

Example #1 – VBA Font Color

We have sample text in an Excel sheet with the text “VBA Font Color” in cell B3 as shown below. As we can see, the font color is default black in nature.

Font Color Example 1

We need a module to apply the VBA code for changing the Color of fonts for the above-shown text.

Step 1: For this, go to the VBA window and click on the Module option available in the Insert menu option, as shown below.

Module for VBA Font Color

Step 2: Once we do that, we will get the blank window of the Module. In that, start writing a subcategory of VBA Font Color or any other name as per your need, as shown below.

Code:

Sub VBAFontColor2()

End Sub

VBA Font Color Exmaple 1.1

Step 3: First, select the range of the cell where the text is located. Here, our range will be cell B3, and that will be written, followed by the “.Select” command as shown below.

Code:

Sub VBAFontColor2()

Range("B3").Select

End Sub

VBA Font Color Exmaple 1.2

Step 4: As we need to change the font color, we will select the Font command with the help of Selection, as shown below.

Code:

Sub VBAFontColor2()

Range("B3").Select
Selection.Font

End Sub

VBA Font Color Exmaple 1.3

Step 5: Afterward, we will select the command Color separated by a dot (.) as shown below.

Code:

Sub VBAFontColor2()

Range("B3").Select
Selection.Font.Color

End Sub

VBA Font Color Exmaple 1.4

To understand any color’s formation in VBA, we have RGB, i.e., Red-Green-Blue. Numeric values of each Color range from 0 to 255. Suppose we need to change to a color font to Black; then the RGB value will be RGB(0, 0, 0). As we already have the black color font, we will try to select some other color.

Step 6: Let’s give the largest value to Green Color, the least to Red, and zero to Blue Color. As per that, consider Red at 20, Green at 230, and Blue at zero, as shown below.

Code:

Sub VBAFontColor2()

Range("B3").Select
Selection.Font.Color = RGB(20, 230, 0)

End Sub
VBA Font Color Exmaple 1.5

Step 7: Now compile the code to find if it has any errors, and then run by clicking on the play button located below the menu bar. We will apply font color for the text in cell B3, which has now changed from Black to Green Color.

VBA Font Example1

Example #2 – VBA Font Color

There is another way of changing the font color in VBA. For this, we will consider the same text shown in example-1, located in cell B3.

Color Example 2

Apart from RGB, we can change the Color of fonts with the keyword “vb” followed by the name of the Color. But by this process, we can only get the main basic Color as the font color. With the help of RGB, we could get the Color of any shade just by putting the different values for Red, Green, and Blue colors.

The Colors used with vb are Black, Blue, Cyan, Green, Magenta, Red, White, and Yellow. And how to select the Color in format is shown below.

diff color

Step 1: To apply this, go to VBA to create the subcategory in the name of VBA Font Color or any other name in a new module, as shown below.

Code:

Sub VBAFontColor3()

End Sub

VBA Font Color Exmaple 2.1

Step 2: Select the range of cells we need to change the font color, as shown below.

Code:

Sub VBAFontColor3()

Range("B3").Select

End Sub

VBA color Example 2.1

Step 3: In the same manner we have seen in example-1, use the selection function with Font and Color to activate them.

Code:

Sub VBAFontColor3()

Range("B3").Select
Selection.Font.Color

End Sub

VBA color Example 2.2

Step 4: It lets the Color of the font from Black to Cyan. For this, select Cyan color by vbCyan, as shown below.

Code:

Sub VBAFontColor3()

Range("B3").Select
Selection.Font.Color = vbCyan

End Sub

VBA color Example 2.3

Step 5: If required, we can compile and run the code. The font color of the text in cell B3 is changed from Black to Cyan.

VBA Example 2

Example #3 – VBA Font Color

Microsoft has defined a variety of Colors in different numbers. These are 56 in number. We can select any color code between 1 to 56 to change the font color of any cell. These color codes are shown below.

100 color

Step 1: Go to the VBA window and open a new module. In that, write the Sub Category of VBA Font Color as shown below.

Code:

Sub VBAFontColor4()

End Sub

VBA Font Color Exmaple 3.1

Step 2: For this example, we will select the same text as seen in the above examples. Now select the range of the cell, which is B3, as shown below.

Code:

Sub VBAFontColor4()

Range("B3").Select

End Sub

Exmaple 3.2

Step 3: Select the Font function with the Selection command in the second line.

Code:

Sub VBAFontColor4()

Range("B3").Select
Selection.Font.

End Sub

VBA color Example 3.4

Step 4: To select and apply the above-shown color code, we must select the ColorIndex function instead of Color, which we used in examples 1 and 2.

Code:

Sub VBAFontColor4()

Range("B3").Select
Selection.Font.ColorIndex = 46

End Sub

Example 3.5

And at last, select the color code we need to see in a selected range of cells. Let’s select color code 46 which is used for the Orange color.

Step 5: Now run the code to see the change. The color font in cell B3 is now changed from black to orange.

VBA Font Example 3

Pros of VBA Font Color

  • It is easy to implement.
  • With the help of RGB, we can change the color of any shade we want.
  • It helps create the dashboard where we need to show the different types of data in a different colors with the help of VBA.

Things to Remember

  • It is always recommended to use RGB when we do not know the color code. By giving a different color range from 0 to 255 in RGB, we can create any color from dark to a bright shade of our choice.
  • Saving the file in Macro Enable Excel helps to use and visit the written code multiple times.
  • Although changing font color in Excel is the easiest way to do, automating this activity in huge work can save time and avoid the chances when the file may crash or hang.

Recommended Articles

This is a guide to VBA Font Color. Here we discuss how to use Excel VBA Font Color, a few practical examples, and a downloadable Excel template. You can also go through our other suggested articles –

  1. VBA While Loop
  2. VBA Remove Duplicates
  3. Excel VBA MsgBox
  4. VBA Sleep

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Web Development & many more.

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

Download VBA Font Color Excel Template

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - ENROLL NOW