Vba Programming Basics

You can reference a specific cell in a worksheet with the Cells property. With this property, you can reference a specific cell in a worksheet using one of two methods. The first method enables you to specify the row and column number of the appropriate cell. By specifying the row and column number to reference cell A5, you can type Cells(5,1). This is intepreted 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 REFERENCE

NUMERIC REFERENCE

A1

Cells(1,1)

Cells(1)

A2

Cells(2,1)

Cells(257)

C5

Cells(5,3)

Cells(515)

it View Insert Format Debug Run Tools Add-Ins Window Hel[

it View Insert Format Debug Run Tools Add-Ins Window Hel[

■ The result of the mathematical calculation displays in the location specified in step 4.

□ Type Cells(1,1) = Var1/Var2, replacing Cells(1,1) with the location for the result and Varl and Var2 with the variables declared in step 2.

0 Press Enter.

■ You can replace the / (division operator) with any of the VBA mathematical operators.

Q Switch to Excel and run the macro.

■ The result of the mathematical calculation displays in the location specified in step 4.

0 0

Post a comment