Microsoft Office Tutorials and References
In Depth Information
Determining a Cell’s Data Type
The following FILLCOLOR function returns an integer that corresponds to the color index of the
cell’s interior (the cell’s fill color). If the cell’s interior is not filled, the function returns –4142. The
ColorIndex property ranges from 0 to 56.
Function FILLCOLOR(cell As Range) As Long
‘ Returns a value corresponding to
‘ cell’s interior color
Application.Volatile True
FILLCOLOR = cell.Range(“A1”).Interior.ColorIndex
End Function
If a cell is part of a table that uses a style, the FILLCOLOR function does not return the
correct color. Similarly, a fill color that results from conditional formatting is not
returned by this function.
The following function returns the number format string for a cell:
Function NUMBERFORMAT(cell As Range) As String
‘ Returns a string that represents
‘ the cell’s number format
Application.Volatile True
NUMBERFORMAT = cell.Range(“A1”).NumberFormat
End Function
If the cell uses the default number format, the function returns the string General.
Determining a Cell’s Data Type
Excel provides a number of built-in functions that can help determine the type of data contained
in a cell. These include ISTEXT, ISLOGICAL, and ISERROR. In addition, VBA includes functions
The following function accepts a range argument and returns a string ( Blank, Text, Logical, Error,
Date, Time, or Value ) that describes the data type of the upper-left cell in the range:
Function CELLTYPE(cell As Range) As String
‘ Returns the cell type of the upper-left
‘ cell in a range
Dim UpperLeft As Range
Application.Volatile True
Set UpperLeft = cell.Range(“A1”)
Select Case True
Search JabSto ::

Custom Search