Page 195 - Excel Data Analysis
P. 195
10 537547 Ch09.qxd 3/4/03 12:13 PM Page 181
AUTOMATING ACTIONS WITH MACROS 9
You can reference a specific cell in a worksheet with the Cells
property using one of two methods. The first method enables
you to specify the row and column number of the appropriate
cell. For example, to specify the row and column number to
reference cell A5, you type Cells(5,1). This is interpreted as the
cell in the fifth row and the first column. Using the cell
reference method, you can reference rows from 1 to 65,536 and
columns from 1 to 256.
The second method numbers each cell on the worksheet
between 1 and 16,777,216 (65,536 rows by 256 columns). With
this method, you specify one numeric value for the cell, which
may confuse you at first. For example, cell M1 is referenced as
Cells(13).
EXCEL CELL COLUMN/ROW NUMERIC
REFERENCE REFERENCE
A1 Cells(1,1) Cells(1)
A2 Cells(2,1) Cells(257)
C5 Cells(5,3) Cells(515)
‡ Press Enter. · Type an equal sign (=) and — Switch to Excel and run ■ The declared value
a starting value for your the corresponding macro. displays in the cell specified
° Type your variable name.
variable. in step 10.
‚ Set the cell location equal
to the name of your variable.
181