RGB Function

Description

Returns a whole number representing an RGB color value.

Syntax

RGB (red, green, blue)

The RGB function syntax has these named-argument parts:

Part

Description

red

Whole number in the range 0 to 255, inclusive, that represents the red component of the color.

green

Whole number in the range 0 to 255, inclusive, that represents the green component of the color.

blue

Whole number in the range 0 to 255, inclusive, that represents the blue component of the color.


Remarks

Application methods and properties that accept a color specification expect that specification to be a whole number representing an RGB color value. An RGB color value specifies the relative intensity of red, green, and blue, which combined cause a specific color to be displayed.

The value for any argument to RGB that exceeds 255 is assumed to be 255.

The following table lists some standard colors and the red, green and blue values they include:

Color

Red Value

Green Value

Blue Value

Black

0

0

0

Blue

0

0

255

Green

0

255

0

Cyan

0

255

255

Red

255

0

0

Magenta

255

0

255

Yellow

255

255

0

White

255

255

255


Note

The RGB values returned by this function are incompatible with those used by the Macintosh operating system. They may be used within the context of Microsoft applications for the Macintosh, but should not be used when communicating color changes directly to the Macintosh operating system.

Example

This example shows how the RGB function is used to return a whole number representing an RGB color value. It is used for those application methods and properties that accept a color specification. The object MyObject and its property are used here for illustration purposes only.


Red = RGB(255, 0, 0)    ' Return the value for Red.
I = 75    ' Initialize offset.
RGBValue = RGB(I, 64 + I, 128 + I)     ' Same as RGB(75, 139, 203).
MyObject.Color = RGB(255, 0, 0)    ' Set the Color property of 
    ' MyObject to Red.

This example sets the gridline color in the active window in BOOK1.XLS to red.


Workbooks("BOOK1.XLS").Worksheets("Sheet1").Activate
ActiveWindow.GridlineColor = RGB(255,0,0)

This example sets the color of the tick labels on the value axis in Chart1 to green.


Charts("Chart1").Axes(xlValue).TickLabels.Font.Color = RGB(0, 255, 0)

This example sets the marker background and foreground colors for the second point in series one in Chart1.


With Charts("Chart1").SeriesCollection(1).Points(2)
    .MarkerBackgroundColor = RGB(0,255,0)    ' green
    .MarkerForegroundColor = RGB(255,0,0)    ' red
End With

This example sets the interior pattern color for rectangle one on Sheet1 to red.


With Worksheets("Sheet1").Rectangles(1).Interior
    .Pattern = xlGrid
    .PatternColor = RGB(255,0,0)
End With