How to use the CELL function
The CELL function gets information about the formatting, location, or the contents of a cell.
The formula example above in cell C3 returns a value determined by the contents of the cell.
Return value | Cell content |
l | text |
b | blank |
v | anything else |
Formula in cell C3:
Excel Function Syntax
CELL(info_type, [reference])
Arguments
info_type | Required. A value that determines the type of cell information the function returns. |
List of Info_type arguments and what they do.
info_type | Returns |
"address" | Reference of the first cell in reference, as text. |
"col" | Column number of the cell in reference. |
"color" | The value 1 if the cell is formatted in color for negative values; otherwise returns 0 (zero). |
"contents" | Value of the upper-left cell in reference; not a formula. |
"filename" | Filename (including full path) of the file that contains reference, as text. Returns empty text ("") if the worksheet that contains reference has not yet been saved. |
"format" | Text value corresponding to the number format of the cell. The text values for the various formats are shown in the following table. Returns "-" at the end of the text value if the cell is formatted in color for negative values. Returns "()" at the end of the text value if the cell is formatted with parentheses for positive or all values. |
"parentheses" | The value 1 if the cell is formatted with parentheses for positive or all values; otherwise returns 0. |
"prefix" | Text value corresponding to the "label prefix" of the cell. Returns single quotation mark (') if the cell contains left-aligned text, double quotation mark (") if the cell contains right-aligned text, caret (^) if the cell contains centered text, backslash (\) if the cell contains fill-aligned text, and empty text ("") if the cell contains anything else. |
"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. |
"type" | Text value corresponding to the type of data in the cell. Returns "b" for blank if the cell is empty, "l" for label if the cell contains a text constant, and "v" for value if the cell contains anything else. |
"width" | Column width of the cell, rounded off to an integer. Each unit of column width is equal to the width of one character in the default font size. |
The second argument in the CELL function is [Reference].
[Reference] | Optional. The cell that you want information about. If omitted, the information specified in the Info_type argument is returned for the last cell that was changed. |
Info_type "format" returns the following codes for different cell formatting settings.
Excel format | Returns |
General | "G" |
0 | "F0" |
#,##0 | ",0" |
0.00 | "F2" |
#,##0.00 | ",2" |
$#,##0_);($#,##0) | "C0" |
$#,##0_);[Red]($#,##0) | "C0-" |
$#,##0.00_);($#,##0.00) | "C2" |
$#,##0.00_);[Red]($#,##0.00) | "C2-" |
0% | "P0" |
0.00% | "P2" |
0.00E+00 | "S2" |
# ?/? or # ??/?? | "G" |
m/d/yy or m/d/yy h:mm or mm/dd/yy | "D4" |
d-mmm-yy or dd-mmm-yy | "D1" |
d-mmm or dd-mmm | "D2" |
mmm-yy | "D3" |
mm/dd | "D5" |
h:mm AM/PM | "D7" |
h:mm:ss AM/PM | "D6" |
h:mm | "D9" |
h:mm:ss | "D8" |
How to calculate the intersection of two cell ranges?
The CELL function is able to return the cell reference from a cell range based on two intersecting cell references.
Formula in cell B13:
The space character can be used as an intersect operator in Excel. The formula in cell B13 returns the top-left cell address of the intersecting cell references.
The image above shows how to calculate the address of two intersecting cell ranges using a VBA macro. The message box shows the address of the entire cell range.
VBA code
Sub TwoCellRanges() MsgBox "Intersecting cell range: " & Application.Intersect(Range("B2:C7"), Range("C5:E10")).Address End Sub
Where to put the code?
- Copy above VBA code.
- Press shortcut keys Alt + F11 to open the Visual Basic Editor.
- Click on "Insert" on the menu.
- Click "Module".
- Paste code to window.
- Exit VB Editor and return to Excel.
Functions in 'Information'
The CELL function function is one of many functions in the 'Information' category.
The CELL function gets information about the formatting, location, or the contents of a cell. The formula example above in […]
How to use the ERROR.TYPE function
The ERROR.TYPE function returns a number that represents one of the error values in Excel. Formula in cell C3: =ERROR.TYPE(B3) […]
The INFO function returns information about the current operating environment, file path, number of active worksheets, Excel version etc. Excel […]
How to use the ISBLANK function
The ISBLANK function returns TRUE if the argument is an empty cell, returns FALSE if not. Excel Function Syntax ISBLANK(value) […]
The ISERR function returns TRUE if a cell returns an error, except error value #N/A. Formula in cell C6: =ISERR(B6) […]
How to use the ISERROR function
The ISERROR function returns TRUE if a cell returns an error. Formula in cell D3: =ISERROR(B3) Excel Function Syntax ISERROR(value) […]
How to use the ISFORMULA function
The ISFORMULA function returns TRUE if a cell contains a formula, FALSE if text, number or boolean value. Formula in […]
How to use the ISLOGICAL function
The ISLOGICAL function returns TRUE if value is boolean. A boolean value is either TRUE or FALSE. Formula in cell C3: […]
The ISNA function returns TRUE if value is a #N/A error. Formula in cell C3: =ISNA(B3) Excel Function Syntax ISNA(value) […]
How to use the ISNONTEXT function
The ISNONTEXT function returns TRUE if value is not text, also returns TRUE if cell is empty. Formula in cell […]
How to use the ISNUMBER function
The ISNUMBER function checks if a value is a number, returns TRUE or FALSE. Formula in cell D3: =ISNUMBER(B3) Excel […]
The ISODD function returns TRUE if a cell contains an odd number, FALSE if even number. Formula in cell C6: […]
The ISREF function returns TRUE if value refers to a reference. Formula in cell C3: =ISREF(B3) Excel Function Syntax ISREF(value) […]
How to use the ISTEXT function
The ISTEXT function returns TRUE if value is text. Formula in cell C3: =ISTEXT(B3) Excel Function Syntax ISTEXT(value) Arguments value […]
The N function returns a value converted into a number. Formula in cell C3: =N(B3) The N function returns the […]
The NA() function returns the error value #N/A meaning "value is not available". Formula in cell B3: =NA() Excel Function […]
The SHEET function returns the sheet number of the cell reference sheet. Formula in cell D3: =SHEET(A1) Excel Function Syntax […]
How to use the SHEETS function
The SHEETS function returns the number of sheets in a reference. It returns the number of sheets in a workbook if […]
Use TYPE to find out what type of data is returned by a function or formula. Formula in cell C3: […]
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form