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

    Range("A1").RowHeight = 60 

    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)

1 comment:

  1. I am an Ms Excel champ and I Know different sort of formula's in the program and I even know that how you can make pivot table on Excel, but i am in a deep trouble now a days. I have to assign my thesis to online thesis writing service because I don't want to regret at all in the future.


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