VBA: Color Reference For Colorindex

Automate Excel

VBA: Color Reference For Colorindex

When using VBA to code the Colorindex (or background color) of a cell it is useful to know what integer will equal what color. Below is a reference picture which shows the color and lists it’s respective Colorindex. aka VBA Color Palette

ColorReference


Here’s the code to make one for yourself, or just bookmark the permalink:

Sub ColorRef()
Dim x As Integer

For x = 1 To 56

If x < 29 Then
Cells(x, 1).Interior.ColorIndex = x
Cells(x, 2) = x
Else
Cells(x - 28, 3).Interior.ColorIndex = x
Cells(x - 28, 4) = x
End If

Next x

End Sub

Related posts

2 Responses

  1. Standard Says:

    Thanks, works great.

    However, Why does excel give 56 numbers to 35 colors?

    Thanks again.

  2. VBA: Change a Cells Background Color Says:

    [...] an easy way to determine what number equals what color? Check out Color Reference For Colorindex. Posted in Cells, Columns & Rows [...]

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.