VBA Function: RGB

The VBA RGB function returns an integer corresponding to a color in RGB format.

Usage:

RGB(red_value, green_value, blue_value)


Examples of Usage

Using the RGB function to apply a background color to cell A1:

Sub example()

    Range("A1").Interior.Color = RGB(222, 111, 111)
    
End Sub

Using the RGB function to apply a background color to a TextBox control:

Sub example()

    TextBox1.BackColor = RGB(234, 123, 123)
    
End Sub
Examples of RGB values are available on the page of the 729 RGB colors.