ColorIndex Property

Applies To

Border Object, Borders Collection, Font Object, Interior Object.

Description

Returns or sets the color of the border, font, or interior, as shown in the following table. The color is specified as an index value into the current color palette, or the special constant xlAutomatic to use the automatic fill style. Read-write.

Object

ColorIndex

Border

Color of the border.

Borders

Color of all four borders. Returns Null if all four colors are not the same.

Font

Color of the font. Specify xlAutomatic to use the automatic color.

Interior

Color of the interior fill. Set this property to xlNone to specify no fill. Set this property to xlAutomatic to specify the automatic fill (for drawing objects).


Remarks

This property specifies a color as an index into the workbook color palette. You can use the Colors property to return the current color palette.

See Also

Color Property, Colors Property, PatternColor Property.

Example

The following examples assume that you are using the default color palette.

This example changes the font color in cell A1 on Sheet1 to red.


Worksheets("Sheet1").Range("A1").Font.ColorIndex = 3

This example sets the color of the major gridlines for the value axis in Chart1.


With Charts("Chart1").Axes(xlValue)
    If .HasMajorGridlines Then
        .MajorGridlines.Border.ColorIndex = 5    'set color to blue
    End If
End With

This example sets the chart area interior color of Chart1 to red and sets the border color to blue.


With Charts("Chart1").ChartArea
    .Interior.ColorIndex = 3
    .Border.ColorIndex = 5
End With

This example sets the border color of every graphic object on Sheet1 to cyan.


For Each d In Worksheets("Sheet1").DrawingObjects
    d.Border.ColorIndex = 8
Next d