Excel VBA, XlRgbColor

The enum XlRgbColor contains a list of color codes. Although this list is limited but often it is enough to get the job done. If you require more specific colors please see Excel VBA, Color Code. In the example below the color code associated with some of the members of the enum XlRgbColor and its associated color is printed in columns B and C:

Sub main()
Dim i As Integer
'AliceBlue
i = 2
Cells(i, 1) = "rgbAliceBlue"
Cells(i, 2) = XlRgbColor.rgbAliceBlue
Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbAliceBlue
'AntiqueWhite
i = 3
Cells(i, 1) = "rgbAntiqueWhite"
Cells(i, 2) = XlRgbColor.rgbAntiqueWhite
Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbAntiqueWhite
'Aqua
i = 4
Cells(i, 1) = "rgbAqua"
Cells(i, 2) = XlRgbColor.rgbAqua
Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbAqua
'Aquamarine
i = 5
Cells(i, 1) = "rgbAquamarine"
Cells(i, 2) = XlRgbColor.rgbAquamarine
Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbAquamarine
'Azure
i = 6
Cells(i, 1) = "rgbAzure"
Cells(i, 2) = XlRgbColor.rgbAzure
Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbAzure
'Beige
i = 7
Cells(i, 1) = "rgbBeige"
Cells(i, 2) = XlRgbColor.rgbBeige
Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbBeige
'Bisque
i = 8
Cells(i, 1) = "rgbBisque"
Cells(i, 2) = XlRgbColor.rgbBisque
Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbBisque
End Sub

Result:

Excel, VBA, RGB Color Constants

The line below prints the name of the RGB color constant in column A:

Cells(i, 1) = "rgbAliceBlue"

The line below prints the color code associated with the RGB color constant in column B:

Cells(i, 2) = XlRgbColor.rgbAliceBlue

The line below changes the fill color of the cell in column C to the color associated with the RGB color constant:

Range(Cells(i, 3), Cells(i, 3)).Interior.Color _
= XlRgbColor.rgbAliceBlue

You can download the file and code related to this article here.

See also:

Leave a Reply

Your email address will not be published. Required fields are marked *