Cell() Function



The Excel Cell function returns information about a cell in a worksheet. The type of information to be returned is specified as info_type. CELL can get things like address and filename, as well as detailed info about the formatting used in the cell. 


Syntax

The syntax for the CELL function in Microsoft Excel is:

=CELL( type, [range] )

Parameters or Arguments

type

The type of information that you'd like to retrieve for the cell. type can be one of the following values:
Value
Explanation
"address"
Address of the cell. If the cell refers to a range, it is the first cell in the range.
"col"
Column number of the cell.
"color"
Returns 1 if the color is a negative value; Otherwise it returns 0.
"contents"
Contents of the upper-left cell.
"filename"
Filename of the file that contains reference.
"format"
Number format of the cell. See example formats below.
"parentheses"
Returns 1 if the cell is formatted with parentheses; Otherwise, it returns 0.
"prefix"
Label prefix for the cell.
* Returns a single quote (') if the cell is left-aligned.
* Returns a double quote (") if the cell is right-aligned.
* Returns a caret (^) if the cell is center-aligned.
* Returns a back slash (\) if the cell is fill-aligned.
* Returns an empty text value for all others.
"protect"
Returns 1 if the cell is locked. Returns 0 if the cell is not locked.
"row"
Row number of the cell.
"type"
Returns "b" if the cell is empty.
Returns "l" if the cell contains a text constant.
Returns "v" for all others.
"width"
Column width of the cell, rounded to the nearest integer.

"format"
For the "format" value, described above, the values returned are as follows:
Returned Value for "format"
Explanation
"G"
General
"F0"
0
",0"
#,##0
"F2"
0
",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
"G"
# ?/? or # ??/??
"D4"
m/d/yy or m/d/yy h:mm or mm/dd/yy
"D1"
d-mmm-yy or dd-mmm-yy
"D2"
d-mmm or dd-mmm
"D3"
mmm-yy
"D5"
mm/dd
"D6"
h:mm:ss AM/PM
"D7"
h:mm AM/PM
"D8"
h:mm:ss
"D9"
h:mm

range

Optional. It is the cell (or range) that you wish to retrieve information for. If the range parameter is omitted, the CELL function will assume that you are retrieving information for the last cell that was changed.

Examples of the Excel Cell Function

In the following example spreadsheet, the Excel Cell function is used to return different properties of the cell A1. It should be noted that, in the spreadsheet, cell A1 is formatted with the Custom Format   #,##0; [Red] - #,##0.

Formulas:


A
B
1
- 9,999
=CELL( "address", A1 )
2

=CELL( "col", A1 )
3

=CELL( "color", A1 )
4

=CELL( "contents", A1 )
5

=CELL( "filename", A1 )
6

=CELL( "format", A1 )
7

=CELL( "parentheses", A1 )
8

=CELL( "prefix", A1 )
9

=CELL( "protect", A1 )
10

=CELL( "row", A1 )
11

=CELL( "type", A1 )
12

=CELL( "width", A1 )

Results:


A
B
1
- 9,999
$A$1
2

1
3

1
4

-9999
5

C:\[Book1.xlsx]Sheet1
6

,0-
7

0
8


9

1
10

1
11

v
12

8

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.

Note:

If the formatting of cell A1 in the above spreadsheet is changed, the formulas in cells B1-B12 will not immediately recalculate. You can force them to recalculate by pressing the F9 key.

References


Choose() Function


The Excel CHOOSE function returns a value from a list using a given position or index. 



Syntax

The syntax for the CHOOSE function in Microsoft Excel is:

=CHOOSE( position, value1, [value2, ... value_n] )

Parameters or Arguments

position

The position number in the list of values to return. It must be a number between 1 and 29.

value1, value2, ... value_n

A list of up to 29 values. A value can be any one of the following: a number, a cell reference, a defined name, a formula/function, or a text value.

Excel Choose Function Examples


Example 1 - Using the Choose Function to Return a Value

Column A of the following spreadsheet shows the Choose function used to return the following colors, depending on the value of the index_num argument:

1 - red; 2 - blue; 3 - green; 4 - brown

Formulas:


A
1
=CHOOSE( 4, "red", "blue", "green", "brown" )
2
=CHOOSE( 2, "red", "blue", "green", "brown" )
3
=CHOOSE( 3, "red", "blue", "green", "brown" )
4
=CHOOSE( 1, "red", "blue", "green", "brown" )

Results:


A
1
brown
2
blue
3
green
4
red

Example 2 - Using the Choose Function to Return a Cell Reference

The Excel Choose function can also return cell references, as shown in the following example. In this case, the reference that is returned from the Choose function is then provided to the Excel SUM Function.

Formulas:


A
B
C
1
10
3
=SUM( CHOOSE( B1, A1, A1:A2, A1:A3, A1:A4 ) )
2
11


3
12


4
13



Results:


A
B
C
1
10
3
33
2
11


3
12


4
13



In the example above, the Choose function returns the cell reference A1:A3. This is then passed to the SUM function which calculates the sum of the values in the cell range A1:A3 and returns the value 33.

Notes

   If the position is <0, then it will return #NUM error.
   If the position is greater than the supplied number, then it will return #NUM error.
   If the position is non-numeric, then it will return #VALUE error.

References



OR Function