What The CELL!: Info - Typ
What The CELL!: Info - Typ
Excel’s CELL function doesn’t get a lot of press but it can be handy to know.
The CELL Function simply returns information about the formatting, contents
or location of a cell.
The result, D1, refers to the type of format applied to cell A5; ‘D’ for date and 5
for the type of date format, being dd/mm/yyyy.
It might not seem much use at first glance but I’ll show you some applications
for it in a moment.
=CELL(info_type, [reference])
The reference is the cell we want to return information about. It’s an optional
argument and if you omit it Excel will return the information for the last
changed cell. Alternatively, if the reference is for a range of cells then you will
get the information for the upper left cell in the range only.
CELL info_types
info_type Returns
address The address of the first cell in reference, as text. e.g $A$1
col Column number of the cell in reference. e.g. a cell in column C would return 3
The value 1 if the cell is formatted in color for negative values; otherwise returns 0 (zero).
color Note: this is not the color of the text in the cell, it simply indicates if the format of the cell has
special color formatting for negative values.
Filename (including full path) of the file that contains reference, as text. Returns empty text
filename
("") if the worksheet that contains reference has not yet been saved.
Text value corresponding to the number format of the cell. More on this below. Returns:
"-" at the end of the text value if the cell is formatted in color for negative values.
format
"()" at the end of the text value if the cell is formatted with parentheses for positive or
all values.
The value 1 if the cell is formatted with parentheses for positive or all values; otherwise
parentheses
returns 0.
Text value corresponding to the "label prefix" of the cell. Returns:
protect The value 0 if the cell is not locked; otherwise returns 1 if the cell is locked.
row Row number of the cell in reference. e.g. a cell in row 2 would return 2.
Column width of the cell, rounded off to an integer. Each unit of column width is equal to the
width
width of one character in the default font size.
The table below shows the results for some of the different ‘info_types’ for the
values in column A (that is, columns C through H contain CELL formulas which
reference the values in column A):
Format Legend
The ‘Format’ info-type has a range of results. The table below explains what
those results represent:
Result Returned Actual Cell Format (as applied via the Format Cells Dialog Box)
"D1" d/mmm/yy or dd/mmm/yy
"D3" mmm/yy
"D5" mm/dd
"D8" h:mm:ss
"D9" h:mm
"G" General
"F0" 0
",0" #,##0
"F2" 0.00
",2" #,##0.00
"C0" $#,##0_);($#,##0)
"C0-" $#,##0_);[Red]($#,##0)
"C2" $#,##0.00_);($#,##0.00)
"C2-" $#,##0.00_);[Red]($#,##0.00)
"P0" 0%
"P2" 0.00%
"S2" 0.00E+00
1. random dates
2. the letter N
3. the letter I
4. N/A
I’m trying to write a formula that will give me a percentage of the cells that
contain dates out of the total number of cells that I have selected. I would also
like to exclude from the percentage listed above all cells containing N/A. How
would l do that?
And Catalin, our in-house Excel Guru, replied with this solution using the CELL
function:
Assuming that your range is in column A, starting from row 1, use this formula
in cell B1:
Then you can count the results of the CELL formula and calculate the
percentage with this formula:
=COUNTIF(B1:B8,"D*")/(COUNTA(A1:A8)-COUNTIF(A1:A8,"#N/A"))
Of course this formula relies on the cell format matching the data. It is
possible to format a cell containing text as a date which would result in an
error.
=CELL("filename")
Notice how we can omit the reference argument since the file name is not
dependent on one cell.
The result is the file path, file name and sheet name:
This is handy for inserting the file name in my worksheet so that when I print
the report the file path is visible. It helps you find the file months later!
You can put this in the header/footer too but it’s just as easy to use the CELL
function in a cell somewhere.
="'"&MID(CELL("filename"),FIND("]",CELL("filename"))+1,256)&"'!"
'Sheet1'!
Note: with the single apostrophe at each end and an exclamation mark the
worksheet name is ready for use in your formulas. The apostrophes are only
required if your sheet name has a space in it, but it’s handy to put them in
anyway because if you add a space to your sheet name later on your formulas
won’t break.
If you ever use the INDEX function to return a cell reference to a single cell you
might want to verify that the formula is actually returning a cell reference as
opposed to the value in the cell.
You can do so by wrapping the INDEX formula in a CELL function like so:
=CELL("address", INDEX(…MATCH()…))
The CELL function will return the address given by INDEX as opposed to the
value that typically appears.
#NAME?: The #NAME? error will appear if you don’t enter a valid ‘Reference’
argument or if you misspell the function name.