Range Objects, Properties and Methods
- 04:38
How to apply methods to range objects to perform actions.
Downloads
No associated resources to download.
Transcript
Let's explore some of the properties and methods of the range object.
The offset method has two parameters, the row offset and the column offset very similar to the Excel function.
Positive numbers denote moves downward in rows and across to the right in columns and negative numbers.
Denote moves up rows or across to the left in columns.
In the example, the first line of code specifies the range object, the range B2 to C3 in the Excel sheet.
Note, the VBA syntax requires the range to be bound by quotation marks.
The full stop or period is used to specify the offset method of the range object.
Here we want the range to be offset by two rows and one column.
Finally, we have full stop or period and then the select method.
The results of this code is that range B2 to C3 is offset by two rows and one column, and this new range is then selected in the Excel spreadsheet.
A range object has a current region property.
The region bounded by any combination of blank rows and columns.
This is very similar to using control shift and the arrow keys in the front end of Excel.
Let's take a look at the line of Excel VBA code.
In this example, the range object is specified range A1 and the range object's. Current region property, the current region of cell, A one stretches all the way down to cell C3.
The current region range.
A1 to C3 is selected using the.select method.
Identifying a current region can be really useful when dealing with input areas.
In a model, a worksheet object has a used range property.
The used range in the front of Excel can be specified by pressing control shift and the end key.
The used range returns the range of used cells on a spreadsheet where the range is bound by the rectangle with the most extreme cells at its corners, the application active sheet property returns an object that represents the active sheet in the active workbook.
The used range property returns, The used range range object in the active sheet.
Identifying a used range is a really efficient way of identifying all of the cells in a data download or identifying all the cells that could have code instructions applied to them in Excel VBA. A range object also has methods or actions we can apply to it.
Let's take a look at two methods of a range object.
Firstly, the copy method, the line of code in the example identifies the range object.
Cell A1 in the spreadsheet and specifies its copy method.
The copy method has one argument.
The destination here, the destination is range A3 or cell A3.
In the spreadsheet. If we run this line of code cell, A one will be copied to cell A3.
The second line of code in the example uses the clear method.
The clear method is a method of the range object.
Again, the range object is identified and then the clear method specified.
If we run this line of code, the contents of cell A1 will be cleared.
It's important to note that when we run Excel VBA code, each line of code is run sequentially.