| < Day Day Up > |
|
For the purposes of formatting, cells are divided into two sections: the interior and the border. And, just as you can change the appearance of the gridlines and sheet tabs of a workbook, you can change the color and fill pattern of the interior of a cell. Changing the fill color of a cell to yellow or light orange can help set off the values in the formatted cells. In fact, as seen in Figure 10-2, many of the Excel AutoFormats use colored cell interiors to set a worksheet's data labels apart from the data itself.
Figure 10-2: AutoFormats make data labels stand out so your worksheet data is easier to read.
You change the color and fill pattern of a cell by setting the properties of the Interior object, which is referenced by the Interior property of a cell. Table 10-7 lists the properties of the Interior object.
Property | Description |
---|---|
Color | Determines the fill color of the interior of a cell using an Excel color constant or an RGB function value |
ColorIndex | Determines the fill color of the interior of a cell using an index value that refers to the Excel color palette |
Pattern | Determines the pattern used to fill the interior of a cell using one of the XlPattern Excel constants: xlPatternAutomatic, xlPatternChecker, xlPatternCrissCross, xlPatternDown, xlPatternGray16, xlPatternGray25, xlPatternGray50, xlPatternGray75, xlPatternGray8, xlPatternGrid, xlPatternHorizontal, xlPatternLightDown, xlPatternLightHorizontal, xlPatternLightUp, xlPatternLightVertical, xlPatternNone, xlPatternSemiGray75, xlPatternSolid, xlPatternUp, or xlPatternVertical |
PatternColor | Determines the color of any fill pattern in the interior of a cell using an Excel color constant or an RGB function value |
PatternColorIndex | Determines the color of any fill pattern in the interior of a cell using an index value that refers to the Excel color palette |
The array of patterns available to you, represented by the Excel constants in the Pattern property's description in the preceding table, are available for viewing by clicking Format, Cells, clicking the Patterns tab, and clicking the Pattern down arrow.
One important thing to know about the Color and ColorIndex properties is that they affect a different aspect of the cell's interior than do the PatternColor and PatternColorIndex properties. The default color for either the PatternColor or PatternColorIndex properties is black (represented in the PatternColorIndex property as the index number 1), but you can change the color of the pattern.
The following procedure changes the fill color of the active cell to blue, adds a pattern of thin, black, horizontal lines, and then changes the color of the fill pattern to white:
Sub ChangePattern()
With ActiveCell
.Interior.ColorIndex = 5
MsgBox ("OK to add the horizontal pattern?")
.Interior.Pattern = xlPatternLightHorizontal
MsgBox ("OK to change the pattern's color?")
.Interior.PatternColorIndex = 2
End With
End Sub
| < Day Day Up > |
|