Excel VBA, RGB
As previously mentioned in the article Excel VBA, Color Code when working with colors in Excel you must know their color code. Though sometimes you may want set the color by using the RGB color model. This can be achieved using the RGB() function. For more information about the RGB model please see RGB Color Model.
The RGB() function receives 3 integers as input. The amount of Red, Green and Blue in the color. The values are between 0 and 255. The RGB() function returns the color code associated with the input parameters.
ColorCode = RGB(Red, Green, Blue)
Red: Integer determining the amount of Red in the color (0~255)
Green: Integer determining the amount of Green in the color (0~255)
Blue: Integer determining the amount of Blue in the color(0~255)
ColorCode: A Long value determining the color code assiociated with the input parameters.
In this example the user inputs the amount of Red, Blue and Green in cell A2, B2 and C2. The fill color of cell D2 is updates with the color code returned by the RGB() function. Below you can see some examples:
Red = 0, Green = 0, Blue = 0:
You can download the file and code related to this article here.
- Excel VBA, Color Code
- Excel VBA, ColorConstants
- Excel VBA, XlRgbColor
- VBA Excel, Colors
- Excel VBA, Color Dialog xlDialogEditColor