Microsoft Office Tutorials and References
In Depth Information
Working with Ranges
You can also determine how many rows or columns are contained in a range. The following
expression calculates the number of columns in the currently selected range:
And, of course, you can also use the Rows property to determine the number of rows in a range.
The following statement counts the number of rows in a range named data and assigns the
number to a variable named RowCount :
RowCount = Range(“data”).Rows.Count
Determining the type of selected range
Excel supports several types of range selections:
h A single cell
h A contiguous range of cells
h One or more entire columns
h One or more entire rows
h The entire worksheet
h Any combination of the preceding (that is, a multiple selection)
As a result, when your VBA procedure processes a user-selected range, you can’t make any
presumptions about what that range might be. For example, the range selection might consist of
two areas, say A1:A10 and C1:C10. (To make a multiple selection, press Ctrl while you select the
ranges with your mouse.)
In the case of a multiple range selection, the Range object comprises separate areas. To
determine whether a selection is a multiple selection, use the Areas method, which returns an Areas
collection. This collection represents all the ranges within a multiple range selection.
You can use an expression like the following to determine whether a selected range has multiple
NumAreas = Selection.Areas.Count
If the NumAreas variable contains a value greater than 1, the selection is a multiple selection.
Search JabSto ::

Custom Search