Formatting Cells

 < 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.

click to expand
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.

Table 10-7: The Interior Object's Properties for Formatting a Cell

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.

click to expand

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 > 



Microsoft Excel 2003 Programming Inside Out
Microsoft Office Excel 2003 Programming Inside Out (Inside Out (Microsoft))
ISBN: 0735619859
EAN: 2147483647
Year: 2006
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net