RGB Function

Returns a Long integer colour value consisting of red, green, and blue components.

Syntax:


RGB (Red, Green, Blue)

Return value:

Long

Parameters:

red: Any integer expression that represents the red component (0-255) of the composite colour.

green: Any integer expression that represents the green component (0-255) of the composite colour.

blue: Any integer expression that represents the blue component (0-255) of the composite colour.

The resulting Long value is calculated with the following formula:
Result = red×65536 + green×256 + blue.

warning

Under VBA compatibility mode (Option VBASupport 1), the Long value is calculated as
Result = red + green×256 + blue×65536
See RGB Function [VBA]


tip

The colour picker dialogue box helps computing red, green and blue components of a composite colour. Changing the colour of text and selecting Custom colour displays the color picker dialogue box.


Error codes:

5 Invalid procedure call

Example:


Sub ExampleColor
Dim lVar As Long
    lVar = rgb(128,0,200)
    MsgBox "The colour " & lVar & " consists of:" & Chr(13) &_
        "red= " & red(lVar) & Chr(13)&_
        "green= " & green(lVar) & Chr(13)&_
        "blue= " & blue(lVar) & Chr(13), 64,"colours"
End Sub

Please support us!