Microsoft Office Tutorials and References
In Depth Information
Figure 19-18. A range with three areas
However, every range is made up of one or more areas, and the collection of all Range objects that
represent these areas is the Areas collection for the range. To illustrate, consider Figure 19-18 ,
which is the result of calling the following code:
Dim rng As Range
Set rng = ActiveSheet.Cells.SpecialCells( _
xlCellTypeConstants, xlNumbers)
rng.Select
Note that three distinct areas are selected.
Figure 19-18. A range with three areas
We can clear the second area by writing:
rng.Areas(2).Clear
This will clear the cells C4 and D4. ( Areas is a 1-based collection.)
It strikes me as a bit risky to refer to an individual area by index. However, it is perfectly safe to
cycle through all areas using a For loop such as:
Dim rng As Range, r As Range
Set rng = ActiveSheet.Cells.SpecialCells( _
xlCellTypeConstants, xlNumbers)
For Each r In rng.Areas
Debug.Print r.Cells.Count
Next
19.4.2 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:
Range("a1:b4, d2:e2")
is shown as a dark line in Figure 19-19 .
Figure 19-19. Illustrating the Border object
 
 
 
Search JabSto ::




Custom Search