Referencing objects in an object collection

You might have noticed that when we referred to objects in the previous section, we sometimes used singular references to objects and sometimes plural references. For example, consider the reference to the object Worksheets ("that_sheet"). The Worksheets part is written in plural form and therefore is a collection. Any of these Worksheets is a Worksheet singular object. However, the part in parentheses ("that_sheet") refers to a single worksheet in the collection whose name is that_sheet. This is how we reference single objects in a collection. Most Excel objects conform to this characterisation apart from the Range object. This is because a Range collection does not have a homogenous form. A range can be anything from a single cell to a column, a row, a rectangular group of cells, or even a union of a set of non-contiguous cells. For this reason we cannot refer to a Ranges collection. However, we can still refer to a range in a worksheet in a workbook as the following example shows:

Workbooks ("Salesman"). _

Worksheets ("Weeklysales").Range ("monthjno")

This example references the month_no range of cells, of the Weeklysales worksheet, of the SALESMAN workbook.

0 0

Responses

Post a comment