Objects

First up, this section covers a few basics about Object-Oriented Programming (OOP). This not a complete formal treatise on the subject, but it covers what you need to know to work with the objects in Excel.

OOP's basic premise is that you can describe everything known to us as objects. You and I are objects, the world is an object, and the universe is an object. In Excel, a workbook is an object, a worksheet is an object, and a range is an object. These objects are only a small sample of around two hundred object types available to us in Excel. Look at some examples of how to refer to Range objects in VBA code. One simple way to refer to cells B2:C4 is as follows:

Range("B2:C4")

If you give the name Data to a range of cells, you can use that name in a similar way:

Range("Data")

There are also ways to refer to the currently active cell and selection using shortcuts.

In Figure 1-17, ActiveCell refers to the B2 cell, and Selection refers to the range B2:E6. For more information on ActiveCell and Selection, see Chapter 3.