Monday, April 13, 2009

Macros in Excel : Learn Excel VBA : Properties

This in continuation of my earlier post on
   Macros in Excel : Learn Excel VBA : Objects
Macros in Excel : Learn Excel VBA : Methods


Each VBA object has its own properties that controls its appearance. When we talk about range as object typical properties are
   - ColumnWidth
- RowHeight
- Font
- Text
- Value
- Formula
- Borders

Syntax in your macro is
    Object.Property = Value

or
    Range("A1").RowHeight = 60 

or
    Range("A1").FormulaR1C1 = "=R[2]C+R[3]C" 


Following instruction will set the columon width to 25
    Range("A1").ColumnWidth = 25 


In case property is on left hand side of = sign it is updated with the new value mentioned on the right hand side of = sign

In case you have property on the right hand side of = sign it means you are reading value from that object. Following statement will set the column width of Cell A2 as 35 considering that Cell A1 has column widht of 25

 Range("A2").ColumnWidth = Range("A1").ColumnWidth + 10 

If you are new to Macros in Excel, Please go through my earlier posts on

1. Automating Tasks in Excel : Using Macros in Excel
2. Recording Excel Macros / Writing excel macros (VBA)

No comments:

Post a Comment

Learn how to create Excel dashboards.
Yogesh Gupta's Excel Tips