The Excel CELL Function
The Excel CELL function returns information about a given cell. This can be information in relation to the contents, formatting or location of the cell.
The format of the function is:
CELL( info_type, reference )
where the arguments are as follows:
|info_type||-||Specifies the type of information to be returned. This can be either:|
|"address"||-||returns the cell reference, as text|
|"col"||-||returns the cell's column number|
|"color"||-||returns 1 if the cell is formatted so that negative values are colored, or 0 otherwise|
|"contents"||-||returns the value of the cell (not a formula)|
|"filename"||-||returns the full path and filename of the workbook and worksheet that the supplied cell is in|
(returns "" (blank) if the workbook containing the cell has not yet been saved)
|"format"||-||returns a text value representing the formatting style of the cell. This may be either:|
|"G"||General Format or # ?/? or # ??/??|
|",0"||#,##0||"D2"||d-mmm or dd-mmm|
|",2"||#,##0.00||"D4"||m/d/yy or mm/dd/yy or|
(no decimal places)
(2 decimal places)
|Added to the end of Format Types:|
|"-"||indicates cell is formatted in color for negative values|
|"()"||indicates cell is formatted with parentheses for positive or all values|
|"parentheses"||-||returns 1 if the cell is formatted with parentheses for positive or all values; returns 0 otherwise|
|"prefix"||-||returns a text value corresponding to the 'label prefix' of the cell|
|"protect"||-||returns 1 if the cell is locked and 0 otherwise|
|"row"||-||returns the cell's row number|
|"type"||-||returns a text value corresponding to the type of data in the cell. This can be either "b" for blank (or empty); "l" for label (ie. text constant), or "v" for value (for any other data type)|
|"width"||-||returns the cell's column width|
The cell that the information is to be returned for.Note:
|-||If a range of cells is supplied, the returned information relates to the top left cell of the range|
|-||If the reference is omitted, then the returned information relates to the last cell that was changed|
Examples of the Excel Cell Function
The following spreadsheets shows examples, of the Excel Cell function being used to return different properties of the cell A1. It should be noted that, in the example spreadsheet below, the cell A1 is formatted with the Custom Format #,##0; [Red] - #,##0
(see the Excel Formatting page for more information on different formatting types).
If the formatting of cell A1 in the above spreadsheet is changed, the formulas in cells B1-B12 will not automatically recalculate. You can force them to recalculate by pressing the F9 key.
Note that, in cell B6 of the above example spreadsheet, the "format" type is returned as ",0-". This is comprised of two parts: the ",0" part, which represents the #,##0 number format, and the "-" part, which indicates that the cell is formatted in color for negative values.
Further information and examples of the Excel Cell Function can be found on the Microsoft Office website.
Excel Cell Function Common Error
If you get an error returned from the Excel Cell Function, this is likely to be the Excel #VALUE! error :
|#VALUE!||-||Occurs if the supplied info_type argument is not one of the recognised types (see the table at the top of this page)|