WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Free Tutorials
  • Certification Courses
  • Excel VBA All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA Font Color

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 excel, 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 code 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

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.

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

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 RGB 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 –

  • VBA Examples
  • VBA ChDir
  • Alternate Row Color in Excel
  • Free VBA Online Course
4 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

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

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

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

Login

Forgot Password?

WallStreetMojo

Download VBA Font Color Excel Template

New Year Offer - VBA Training Course (6 courses, 35+ hours video) View More