Microsoft Office Tutorials and References
In Depth Information
19.2.1 Range Property
Dependents
PageRange
Union
Destination
PageRangeCells
UsedRange
DirectDependents
Precedents
VisibleRange
DirectPrecedents
Previous
Let us take a look at some of the more prominent ways to define a Range object.
19.2.1 Range Property
The Range property applies to the Application, Range, and Worksheet objects. Note that:
Application.Range
is equivalent to:
ActiveSheet.Range
When Range is used without qualification within the code module of a worksheet, then it is
applied to that sheet. When Range is used without qualification in a code module for a workbook,
then it applies to the active worksheet in that workbook.
Thus, for example, if the following code appears in the code module for Sheet2:
Worksheets(1).Activate
Range("D1").Value = "test"
then its execution first activates Sheet1, but still places the word "test" in cell D1 of Sheet2.
Because this makes code difficult to read, I suggest that you always qualify your use of the Range
property.
The Range property has two distinct syntaxes. The first syntax is:
object .Range( Name )
where Name is the name of the range. It must be an A1-style reference and can include the range
operator (a colon), the intersection operator (a space), or the union operator (a comma). Any dollar
signs in Name are ignored. We can also use the name of a named range.
To illustrate, here are some examples:
Range("A2")
Range("A2:B3")
Range("A2:F3 A1:D5") ' An intersection
Range("A2:F3, A1:D5") ' A union
Of course, we can use the ConvertFormula method to convert a formula from R1C1 style to A1
style before applying the Range property, as in:
Range(Application.ConvertFormula("R2C5:R6C9", xlR1C1, xlA1))
Finally, if TestRange is the name of a range, then we may write:
Range(Application.Names("TestRange"))
Search JabSto ::




Custom Search