RGB Function Description
The VBA RGB function returns a Long number representing an RGB color.
Syntax
The syntax for the RGB function in VBA is:
RGB( red, green, blue )
Parameters
red
Number in the range 0–255 representing the red component of the color.
green
Number in the range 0–255 representing the green component of the color.
blue
Number in the range 0–255 representing the blue component of the color.
Other Notes
Read more here on how to use the RGB function to set Cell Interior, Font and Border colors in Excel.
Example usage
The RGB function can be used in Excel VBA code to set the Color of an Excel Cell Interior (background), Font or Border. Let’s look at some VBA RGB function examples:
RGB(255,255,0) 'Result: 65535 (yellow) RGB(255,255,0) 'Result: 255 (red) Range("A1").Interior.Color = RGB(0, 0, 255) 'Set cell A1 background to blue