Search notes:

VBA function: RGB

RGB(r, g, b) creates a long value that represents a color.
Such values might be used, for example, in the Excel Object Model to be assigned to the color attribute.
The value of RGB(r, g, b) is r + 256# * g + 256# * 256# * b.

Calculating the R, G and B components of an RGB value

sub rgb_components(rgb_ as long, byRef r as long, byRef g as long, byRef b as long)

    r = rgb_         mod 256
    g = rgb_ \   256 mod 256
    b = rgb_ \ 65536 mod 256

end sub
Using the function:
sub test_func
    dim r as long
    dim g as long
    dim b as long

    rgb_components rgb(200, 220, 250), r, g, b
    debug.print "r = " & r & ", g = " & g & ", b = " & b
end sub

See also

The VBA runtime defines a limited number constants for some color, for example vbRed, vbGreen or vbBlue.
Color properties in the Excel Object Model.
VBA functions
The R function rgb.

Index