Excel vba macro range. The range object which is the representation of a cell or cells on your worksheet is the most important object of excel vba. Whenever we use the object variable we need to use the set keyword and set the object reference to the variable. Every excel user is familiar with selecting a range of cells by shift clicking ctrl clicking or dragging the mouse over a range of cells. As you know vba is used to record run macros and automate the excel tasks and do repetitive tasks faster accurately.
The range property takes the same argument that most excel worksheet functions take eg. To select a range of cells that is the same size as the named range test but that is shifted four rows down and three columns to the right you can use the following example. But how does one select a range in vba. Select an entire range of contiguous cells in a column.
Worksheets sheet1activate range a1h8formula rand range is on the active sheet the following example clears the contents of the range named criteria. In this article ill guide you on how to select a range of cells and activate a particular cell in that range. How to select a range of cells offset from a specified range. The following example shows you how to place a value in a cell using the range property.
Without setting the reference we cannot use an object variable. The range object can include a single cell an entire row or column or multiple cells spread across rows columns. In the context of the excel worksheet the vba range object denotes cells either single or multiple. The range variable in excel vba is an object variable.
The worksheet has a range property which you can use to access cells in vba.