The Interior property

Here's another example of a property that returns an object. A Range object's Interior property returns an Interior object (strange name, but that's what it's called). This type of object referencing works the same way as the Font property (which I describe in the preceding section).

For example, the following statement sets to 3 the ColorIndex property of the Interior object contained in the Range object:

Range("A1").Interior.ColorIndex = 3

In other words, this statement changes the cell's background to red.

The ColorIndex values correspond to the color palette Excel currently uses. The ColorIndex value can be any value from 1 to 56. The easiest way to determine the ColorIndex for a particular color is to record your actions while changing a cell's color. If you need to use standard colors, use the Color property (instead of ColorIndex) along with a built-in constant: vbBlack, vbRed, vbGreen, vbYellow, vbBlue, vbMagenta, vbCyan, or vbWhite. For example, the following statement makes cell A1 yellow:

Range("A1").Interior.Color = vbYellow

Was this article helpful?

0 0

Post a comment