Specify colors with VBA's RGB function. : Range Format « Excel « VBA / Excel / Access / Word

Specify colors with VBA's RGB function.

Sub rgbDemo()
    range("A1").Interior.color = rgb(0, 0, 0) 'black
    range("A2").Interior.color = rgb(255, 0, 0) ' pure red
    range("A3").Interior.color = rgb(0, 0, 255) ' pure blue
    range("A4").Interior.color = rgb(128, 128, 128) ' middle gray
End Sub


Related examples in the same category

1.Format current region
2.The Font property
3.Use the Range and Cells properties of the Worksheet object to return a Range object.
4.Sets to True the Bold property of the Font object contained in the Range object
5.The Interior property:changes the Color property of the Interior object contained in the Range object:
6.Formatting Range: HorizontalAlignment, VerticalAlignment, MergeCells
7.Formatting Range: Font
8.Changes font to bold
9.Changes color of numbers < 100
10.Set the color for whole range
11.Change range border style
12.Change range border color
13.Providing Dynamic Scaling to Your Worksheets
14.Strolling Through the Color Palette
15.Line style: xlContinuous
16.Line style: xlDash
17.Line style: xlDashDot
18.Line style: xlDashDotDot
19.Line style: xlDot
20.Line style: xlDouble
21.Line style: xlLineStyleNone
22.Line style: xlSlantDashDot
23.Using the Interior Object to Alter the Background of a Range
24.Set the underline, color and font name
25.Make column headings bold
26.Add & format totals
27.Format date on report
28.Widen first column to display text
29.Make text in first column bold