Page 59 - Excel for Scientists and Engineers: Numerical Methods
P. 59
36 EXCEL: NUMERICAL METHODS
6. Using the Range keyword with ampersand
TopRow = 2: BtmRow = 12
Range("F" & TopRow & ":G" & BtmRow)
The Range argument evaluates to "F2:G12")
7. Using the Range keyword with two Cells expressions
Range(Cells(1, I), Cells(5, 5))
This expression refers to the range A1 :E5. This method is useful when both
row and column numbers of the reference must be "computed."
8. Using the Range keyword with Cells(index)
Range("A5:Al2").Cells( 3)
This expression refers to cell A7; it provides a way to select individual cells
within a specified range.)
Range("A1: J 1 O').Cells( 13)
Accesses first across rows, then by columns; this example selects cell C2.
9. Using the Range keyword with Offset
Range("Al").Offset(3, 1)
This example selects cell B4.
Range("A1 :Al2").0ffset(3, 1)
This example selects the range B4:B15.
10. Using the Range keyword with Offset and Resize
Range("A1 :Al2").0ffset(3, I).Resize(l , 1)
Use the Resize keyword to select a single cell offset from a range. This
example selects cell B4.
Getting Values from a Worksheet
To transfer values from worksheet cells to a procedure, use a reference to a
worksheet range in an assignment statement like the following.
variablename = ActiveCell.Value
variablename = Worksheets("Sheet1 ").Range("AS").VaIue
The Value keyword can usually be omitted: