11.08.2013 Views

Excel's Formula - sisman

Excel's Formula - sisman

Excel's Formula - sisman

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 24: VBA Programming Concepts 665<br />

A cell’s background color is not part of the Font object; it’s stored in the Interior<br />

object. This function returns True if the upper-left cell of its argument is colored red<br />

(vbRed is a built-in constant):<br />

Function ISREDBKGRD(cell)<br />

ISREDBKGRD = cell.Range(“A1”).Interior.Color = vbRed<br />

End Function<br />

The Columns and Rows properties<br />

The Columns and Rows properties work with columns or rows in a range. For example, the following<br />

function returns the number of columns in a range by accessing the Count property:<br />

Function COLUMNCOUNT(rng)<br />

COLUMNCOUNT = rng.Columns.Count<br />

End Function<br />

The EntireRow and EntireColumn properties<br />

The EntireRow and EntireColumn properties enable you to work with an entire row or column<br />

for a particular cell. The following function accepts a single cell argument and then uses the<br />

EntireColumn property to get a range consisting of the cell’s entire column. It then uses the<br />

Excel COUNTA function to return the number of nonempty cells in the column.<br />

Function NONEMPTYCELLSINCOLUMN(cell)<br />

NONEMPTYCELLSINCOLUMN = WorksheetFunction.CountA(cell.EntireColumn)<br />

End Function<br />

You cannot use this function in a formula that’s in the same column as the cell argument. Doing<br />

so will generate a circular reference.<br />

The Hidden property<br />

The Hidden property is used with rows or columns. It returns TRUE if the row or column is hidden.<br />

If you try to access this property for a range that does not consist of an entire row or column,<br />

you get an error. The following function accepts a single cell argument and returns TRUE if<br />

either the cell’s row or the cell’s column is hidden:<br />

Function CELLISHIDDEN(cell)<br />

If cell.EntireRow.Hidden Or cell.EntireColumn.Hidden Then<br />

CELLISHIDDEN = True<br />

Else<br />

CELLISHIDDEN = False<br />

End If<br />

End Function

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!