Excel VBA Range
The Excel VBA Range object represents a cell or multiple cells in the Worksheet. This object is very important object in Excel VBA.
In Excel VBA, the Range is also called the property of an individual cell or group of cells in any row or column. It is considered as a data set.
To use range function, we need to know about three basic things in Excel VBA, such as:
Properties and Methods are used to manipulate these cell values.
VBA follows the object hierarchy structure to define objects. We will follow the below structure:
NOTE: We connect the objects at each of the different levels by using the (.) dot.
The Worksheet has a range of property which are used to access cells. The range property takes the same argument to perform the most excel worksheet operations, such as "A1", "A3:C6" and more.
Refer Range Object by Range property
Range property is applied to two different types of objects, such as:
The syntax for Range Property:
For example: MsgBox Worksheet("sheet1").Range("A1").Value
We can perform many tasks by using the Range property. And these tasks refer to:
Refer to a single cell using the Worksheet.Range property:
Step 1: First, open Excel.
Step 2: In this step
Step 3: Click on the Macro button from the menu.
Step 4: Now, it will open the VBA code editor and write your code.
Step 5: Save the file and execute the code.
Step 6: After the execution of the code, the cell "A1" is selected automatically.
To apply another range object here is the code syntax:
Cell property is similar to the Range, but the only difference is that it has an "item" property, which is used to reference the cells on the spreadsheet. Cell property is beneficial for the programming loop.
Range Offset Property
Range offset property selects the rows or columns and moves away from its original position. Cells are selected on the basis of Range declared.
The offset property will move A1 cell away to one row and one column. The value of the rowoffset or columnoffset can change as per requirement. And we can also move cells backward by using a negative value (-1).