Here are the most important ways of identifying ranges (there are other ways!)
Selection |
The current selection (highlighted area) |
Range("a1..a10") |
A specific range, defined by cell references |
Range("myrange") |
A specific range, defined a named range |
ActiveCell.Range("a1..a10") |
The first 10 cells below and including the active cell. In this case, the "a1..a10" reference is relative to the current cell. |
Cells |
The entire worksheet |
Since all the above return a range, they all support the same methods and properties. For example:
Sub TestRange
Selection.Font.Bold = True
Range("a1..a10").Font.Underline = True
Cells.Font.Size = 10 ' the whole sheet!
Range("b1..b10").Value = "test"
Range("c1..c10").Formula = "=a1 * 10"
End Sub
Note the last line of the example specifies a formula. This does not increment cell references down the column (e.g. cell c2 will contain "=a1 * 10" just like cell c1). If you want to increment the references, do the following:
Range("c1").Formula = "=a1 * 10"
Range("c1").Copy()
Range("c2..c10").Paste()
This results in cell c2 containing "=a2 * 10".