The Borders Collection

Every range has a set of borders. For instance, the bottom border consists of the bottom borders of all of the cells that one would encounter by looking up at the range from the bottom of the worksheet. (Imagine moving up each column of the sheet until you encounter a cell in the range.) For example, the bottom border of the range:

is shown as a dark line in Figure 19-19.

Figure 19-19. Illustrating the Border object

Tea267 ly®

A | B

C D E

1

2

5

The Borders property of the Range object returns a Borders collection for the range. This collection contains several Border objects, indexed by the following constants:

Enum XlBordersIndex xlDiagonalDown = 5 xlDiagonalUp = 6 xlEdgeLeft = 7 xlEdgeTop = 8 xlEdgeBottom = 9 xlEdgeRight = 10 xllnsideVertical = 11 xllnsideHorizontal = 12 End Enum

(The Excel help documentation refers to these as XlBorderType constants.)

To illustrate, the following code sets the interior color of the range shown in Figure 19-19 to a gray scale and sets the bottom border to thick red (shown as black in the figure). Note the use of nested With statements:

.Interior.Color = RGB(196, 196, 196) With .Borders(xlEdgeBottom) .Weight = xlThick .Color = RGB(2 55, 0, 0) End With End With

Figure 19-20 shows the results of changing the constant xlEdgeBottom to xlDiagonalDown, while Figure 19-21 shows the results of changing the constant to xllnsideVertical.

Figure 19-20. The xlDiagonalDown constant

Figure 19-21. The xlInsideVertical constant

A

B C D

E

1

2 3

4

Figure 19-21. The xlInsideVertical constant

0 0

Post a comment