Excel VBA color code list – ColorIndex, RGB color, VB color

This Excel tutorial collects the VBA color code list for reference purpose, which includes ColorIndex, RGB color, VB color.

Excel ColorIndex

VBA Excel ColorIndex Property is to set color or get color for Objects like Cell color and Shape color. ColorIndex offers 56 basic colors plus the following special numbers.

ColorIndex Value Explanation
-4142 / xlColorIndexNone / xlNone No fill
-4105 / xlColorIndexAutomatic / xlAutomatic Default color (white)

colorindex_10

Example 1: Set Cell A1 font color to red

Range("A1").Font.ColorIndex = 3

Example 2: Set Cell A1 back color to red

Range("A1").Interior.ColorIndex = 3

Example 3: Set Cell A1 border color to red

Range("A1").Borders.ColorIndex=3

Example 4: Get Cell A1 ColorIndex

col = Range("A1").Interior.ColorIndex

Excel RGB color

VBA Excel RGB Property is a color Property of Objects, commonly used for Cell color or Shape color.

“RGB” stands for Red Green Blue, which are known as three primary colors, which can be combined to produce other colors. For example, purple is a mix of blue and red.  In RGB Property, you need to give a value (from 0 to 255) for each color in order to mix a new color. For example, Red = 255 means the brightness of color red is 100%.

rgb color

If you try to change a color but you don’t know the color code, you can visit the websites below

http://www.ifreesite.com/color/

http://big-coronasdklua.blogspot.hk/2011/04/rgb.html

 

Example 1: Set Cell A1 font color to red

Range("A1").Font.Color = RGB(255, 0, 0)

Example 2: Set Cell A1 back color to red

Range("A1").Interior.Color = RGB(255, 0, 0)

Example 3: Set Cell A1 border color to red

Range("A1").Borders.Color = RGB(255, 0, 0)

Excel VB color

The simplest way to apply color is using the VB color name, you don’t have to remember which number represents which color, the the color for your choice is very limited.

excel_vbcolor_10

Example: Set Cell A1 font color to red

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

Leave a Reply

Your email address will not be published.