The tutorial shows how to use the CELL function in Excel to retrieve various information about a cell such as cell address, contents, formatting, location, and more.
How do you usually get specific information about a cell in Excel? Someone would check it visually with their own eyes, others would use the ribbon options. But a faster and more reliable way is to use the Excel CELL function. Among other things, it can tell you whether a cell is protected or not, bring a number format and column width, show a full path to the workbook that contains the cell, and a lot more.
The CELL function in Excel returns various information about a cell such as cell contents, formatting, location, etc.
The syntax of the CELL function is as follows:
The following table shows all possible values for the info_type argument accepted by the Excel CELL function.
|"address"||The address of the cell, returned as text.|
|"col"||The column number of the cell.|
|"color"||The number 1 if the cell is color-formatted for negative values; otherwise 0 (zero).|
|"contents"||The value of the cell. If the cell contains a formula, its calculated value is returned.|
|"filename"||The filename and full path to the workbook that contains the cell, returned as text. If the workbook containing the cell has not been saved yet, an empty string ("") is returned.|
|"format"||A special code that corresponds to the number format of the cell. For more information, please see Format codes.|
|"parentheses"||The number 1 if the cell is formatted with parentheses for positive or all values; otherwise 0.|
|"prefix"||One of the following values depending on how text is aligned in the cell:
For numeric values, an empty string (blank cell) is returned regardless of the alignment.
|"protect"||The number 1 if the cell is locked; 0 if the cell is not locked.
Please note, "locked" is not the same as "protected". The Locked attributed is pre-selected for all cells in Excel by default. To protect a cell from editing or deleting, you need to protect the worksheet.
|"row"||The row number of the cell.|
|"type"||One of the following text values corresponding to the data type in the cell:
|"width"||The column width of the cell rounded to the nearest integer. Please see Excel column width for more information about the width units.|
As an example, let's use the Excel CELL function to return different properties of cell A2 that contains the text value in the General format:
|2||Apple||=CELL("address", $A$2)||$A$2||Cell address as an absolute reference|
|3||=CELL("col", $A$2)||1||Column 1|
|4||=CELL("color", $A$2)||0||Cell is not formatted with color|
|5||=CELL("contents", $A$2)||Apple||Cell value|
|7||=CELL("parentheses", $A$2)||0||The cell is not formatted with parentheses|
|8||=CELL("prefix", $A$2)||^||Centered text|
|9||=CELL("protect", $A$2)||1||The cell is locked (the default state)|
|10||=CELL("row", $A$2)||2||Row 2|
|11||=CELL("type", $A$2)||l||A text constant|
|12||=CELL("width", $A$2)||3||Column width rounded to an integer|
The screenshot shows the results of another Excel CELL formula, which returns different information about cell A2 based on the info_type value in column B. For this, we enter the following formula in C2 and then drag it down to copy the formula to other cells:
With the information you already know, you should have no difficulties with interpreting the formula results, maybe except the format type. And this leads us nicely to the next section of our tutorial.
The below table lists the most typical values that can be returned by a CELL formula with the info_type argument set to "format".
|Currency with no decimal places
$#,##0 or $#,##0_);($#,##0)
|Currency with 2 decimal places
$#,##0.00 or $#,##0.00_);($#,##0.00)
|Percentage with no decimal places
|Percentage with 2 decimal places
# ?/? or # ??/??
|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|
For custom Excel number formats, the CELL function may return other values, and the following tips will help you to interpret them:
To gain more understanding of the format codes, please take a look at the results of the following formula, which is copied across column D:
Note. If you later apply a different format to the referenced cell, you must recalculate the worksheet to update the result of a CELL formula. To recalculate the active worksheet, press Shift + F9 or use any other method described in How to recalculate Excel worksheets.
With the inbuilt info_types, the CELL function can return total 12 different parameters about a cell. In combination with other Excel functions, it is capable of much more. The following examples demonstrate some of the advanced capabilities.
To look up a certain value in one column and return a matching value from another column, you usually use the VLOOKUP function or a more powerful INDEX MATCH combination. In case you also want to know the address of the returned value, put the Index/Match formula in the reference argument of CELL like shown below:
With the lookup value in E2, lookup range A2:A7, and return range B2:B7, the real formula goes as follows:
=CELL("address", INDEX(B2:B7, MATCH(E1,A2:A7,0)))
And returns the absolute cell reference of the lookup result:
Please note that embedding the VLOOKUP function won't work because it returns a cell value, not a reference. The INDEX function also normally displays a cell value, but it returns a cell reference underneath, which the CELL function is able to understand and process.
If you wish not only to get the address of the first match, but also to jump to that match, create a hyperlink to the lookup result by using this generic formula:
In this formula, we again use the classic Index/Match combination to get the first matching value and the CELL function to extract its address. Then, we concatenate the address with the "#" character to tell HYPERLINK that the target cell is in the current sheet.
For our sample dataset, we use the same Index/Match formula as in the previous example and only need to add the desired link name, for example, this one:
=HYPERLINK("#"&CELL("address", INDEX(B2:B7, MATCH(E1,A2:A7,0))), "Go to lookup result")
Instead to creating a hyperlink in a separate cell, you can actually turn the address into a clickable link. For this, embed the same CELL("address", INDEX(…,MATCH()) formula into the last argument of HYPERLINK:
=HYPERLINK("#"&CELL("address", INDEX(B2:B7, MATCH(E1,A2:A7,0))), CELL("address", INDEX(B2:B7, MATCH(E1,A2:A7,0))))
And make sure this lengthy formula produces a laconic and explicit result:
To return a full path to the workbook that contains a referenced cell, use a simple Excel CELL formula with "filename" in the info_type argument:
This will return the file path in this format:
Note. All of the below formulas return the address of the current workbook and worksheet, i.e. the sheet where the formula is located.
To output just the file name, use the following formula:
=MID(CELL("filename"), SEARCH("[", CELL("filename"))+1, SEARCH("]", CELL("filename")) - SEARCH("[", CELL("filename"))-1)
How the formula works:
The file name returned by the Excel CELL function is enclosed in square brackets, and you use the MID function to extract it.
The starting point is the position of the opening square bracket plus 1: SEARCH ("[",CELL("filename"))+1.
The number of characters to extract corresponds to the number of characters between the opening and closing brackets, which is calculated with this formula: SEARCH("]", CELL("filename")) - SEARCH("[", CELL("filename"))-1
To return the sheet name, use one of the following formulas:
=RIGHT(CELL("filename"), LEN(CELL("filename")) - SEARCH("]", CELL("filename")))
=MID(CELL("filename"), SEARCH("]", CELL("filename"))+1, 31)
How the formulas work:
Formula 1: Working from the inside out, we calculate the number of characters in the worksheet name by subtracting the position of the closing bracket returned by SEARCH from the total path length calculated with LEN. Then, we feed this number to the RIGHT function instructing it to pull that many characters from the end of the text string returned by CELL.
Formula 2: We use the MID function to extract just the sheet name beginning with the first character after the closing bracket. The number of characters to extract is supplied as 31, which is the maximum number of characters in worksheet names allowed by the Excel UI (though Excel's xlsx file format permits up to 255 characters in sheet names).
This formula will bring you the file path without the workbook and sheet names:
=LEFT(CELL("filename"), SEARCH("[", CELL("filename"))-1)
How the formula works:
First, you locate the position of the opening square bracket "[" with the SEARCH function and subtract 1. This gives you the number of characters to extract. And then, you use the LEFT function to pull that many characters from the beginning of the text string returned by CELL.
With this formula, you can get a full path to the file including the workbook name, but without the sheet name:
=SUBSTITUTE(LEFT(CELL("filename"), SEARCH("]", CELL("filename"))-1), "[", "")
How the formula works:
The SEARCH function calculates the position of the closing square bracket, from which you subtract 1, and then get the LEFT function to extract that many characters from the beginning of the text string returned by CELL. This effectively cuts off the sheet name, but the opening square bracket remains. To get rid of it, you substitute "[" with an empty string ("").
That's how you use the CELL function in Excel. To have a closer look at the formulas discussed in this tutorial, I invite you to download our Excel CELL Function Sample Workbook.
Thank you for reading and hope to see you on our blog next week!
Table of contents