Range Objects
- 04:18
Understanding range objects in Excel VBA and some of their properties.
Downloads
No associated resources to download.
Transcript
A cell range in Excel can be assigned a value.
The cell may be selected in Excel or it can be coded in VBA without having to be selected in the Excel front end interface. Here, the cell currently selected in the Excel front end is identified as the active cell object in the VBA code.
The active cell object has a value property and this is assigned the value of my cell value.
Alternatively, we can refer to a cell or range of cells currently selected in the Excel front end using the code selection here, all the selected cells will have their value property assigned.
The value of 10.
The number 10 will appear in each cell within the selection Note, the selection code can work with other types of object to identify the cell in VBA code without first selecting it in the Excel front end.
We use the range object.
A cell can be identified using its cell reference, A1 for example, or a name that has been applied to the cell in both circumstances.
Excel VBA syntax requires us to put speech marks around the cell reference.
A range objects can be assigned a text value, a number value or the value property of another range.
Object cells in a range object can also be a property of a range.
The cells object has two parameters, the row index and the column index.
An object's color property can be changed.
There are a number of ways to do this.
We can use the colour index property and assign this one of XL VBAs 56 colour index codes.
For example, colour index three is red colour index, one is black colour index five is blue.
We could also use the colour property and assign the property one of Excel VBAs predefined colours using VB and the colour name.
Eight colours are available here, including VB black, VB blue, VB green, VB red, VB white, and VB yellow. We could also use The the colour property and the equals RGB function.
This is particularly useful for specifying specific colours that are not available.
Using the previous two options, we can use Excel fill more colours and custom to find out the RGB code of a specific colour whilst we are in the front end of Excel.
In the example, the range object is specified range object A one, and its font object.
The font object has a colour property.
The colour property is then assigned to the value of VB blue.
This is one of eight predefined colours in VBA using the same range object.
The interior object is specified.
The interior object has a colour index property.
The colour index property is assigned the value of three.
A colour index of three makes the interior of this cell red.