Using the Range object properties
In this recipe, we will be working with the Range
object's properties. Ranges are objects, and all VBA objects have properties – some are read-only, while others can be edited.
A Range
object has many properties, much more than we normally use. Once you understand the principle, you can apply it to all objects.
Getting ready
Open Excel and activate Book1. Make sure Sheet1 is active. Save the file as Ranges.xlsm
, and then press Alt + F11 to activate the VBA Editor. Insert a new module in the Explorer.
How to do it…
- In the code window, create the following Sub procedure:
Sub RangeProperties() End Sub
- Add the following lines of code:
Sub RangeProperties()     MsgBox Range("A1:B4").Address     Range("A1").Value = 10     MsgBox Range("A1:C1").Count     Range("A1").Font.Bold = True End Sub
- Press...