Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declare a Range relative to the Active Cell with VBA

Tags:

People also ask

How do you assign a range of cells to a variable in VBA?

To use a range or a single cell as a variable, first, you need to declare that variable with the range data type. Once you do that you need to specify a range of a cell to that variable using the range object. This also gives you access to all the properties and methods that you can use with a range.

How do you reference a range in Excel VBA?

If the Excel VBA Range object you want to refer to is a single cell, the syntax is simply “Range(“Cell”)”. For example, if you want to make reference to a single cell, such as A1, type “Range(“A1″)”. You've probably noticed something very important: There is no such thing as a Cell object.


I need to declare a range object relative to the Active Cell. The problem is, the number of rows and columns I want to select is different each time the macro runs.

For example, I have two variables: numRows and numCols.

I want to select a range that has the ActiveCell in the upper-left corner hand has the cell with row ActiveCell.Row + NumRows and column ActiveCell.Column + NumCols in the bottom right (and then I intend to copy this data to an array to speed up my macro).

Any suggestions on how to do this?