VBA RGB function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

RGB Function Description

The VBA RGB function returns a Long number representing an RGB color.


The syntax for the RGB function in VBA is:

RGB( red, green, blue )


Number in the range 0–255 representing the red component of the color.
Number in the range 0–255 representing the green component of the color.
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:

'Result:  65535 (yellow) 

'Result: 255 (red)

Range("A1").Interior.Color = RGB(0, 0, 255) 'Set cell A1 background to blue

Simply the best place to learn VBA!

Error: Please enter a valid email address

Error: Invalid email

Error: Please enter your first name

Error: Please enter your last name

Error: Please enter a username

Error: Please enter a password

Error: Please confirm your password

Error: Password and password confirmation do not match