Page 42 - Excel for Scientists and Engineers: Numerical Methods
P. 42
CHAPTER 2 FUNDAMENTALS OF PROGRAMMING WITH VBA 19
Table 2-1. Some Properties of the Range Object
Column Returns a number corresponding to the first column
in the range.
ColumnWidth Returns or sets the width of all columns in the range.
Count Returns the number of items in the range.
Font Returns or sets the font of the range.
Formula Returns or sets the formula.
Name Returns or sets the name of the range.
NumberFormat Returns or sets the format code for the range.
Row Returns a number corresponding to the first row in
the range.
RowHeight Returns or sets the height of all rows in the range.
Text Returns or sets the text displayed by the cell.
Value Returns or sets the contents of the cell or range.
Using Properties
In a Sub procedure, properties can be set or read. In a Function procedure,
properties can only be read, not changed. To return an object's property, use the
following syntax:
VariableName = ObjectName. ProperfyName
For example, to obtain the number of cells in a range of cells passed to a
function procedure as the argument rng, and store it in the variable NCells, use
the following:
NCells = rng.Count
Properties can have values that are numeric, string, or logical.
Functions
Many of the functions available in VBA are similar to the functions
available in Excel itself. There are 187 VBA functions listed in Excel 2003
VBA Help. Tables 2-2 through 2-4 list some of the more useful ones for
mathematical or scientific calculations.
If you are reasonably familiar with Excel's worksheet functions, you will
have little trouble using VBA's functions. The names of many VBA functions,
such as Abs, Exp, Int, Len, Left, Mid and Right, are identical to the