ID EN
#Text

CODE

Excel Functions

Get the code for a character

Syntax

EXCEL
=CODE(text)

Arguments

Parameter Description
text The text for which you want a numeric code.

Return Value

A numeric code representing a character.

Details

The CODE function returns a numeric code for a given character. For example, CODE("a") returns the code 97: With the character "a" in cell A1, the formula below returns the same result: The CODE function takes a single argument, text, which is normally a text value. If text contains more than one character, the CODE function returns a numeric code for the first character: The CODE function will handle numeric input for the numbers 0-9: Generally speaking, the number returned by CODE is the code for a character in ASCII decimal notation. The CODE function was designed to operate in an ASCII/ANSI world, and only understands how to map characters that correspond to numbers 0-255. For extended character support on modern Unicode systems, see the UNICODE function.

Examples

Example 1

The CODE function returns a numeric code for a given character. For example, CODE("a") returns the code 97:

EXCEL
=CODE("a") // returns 97
Example 2

With the character "a" in cell A1, the formula below returns the same result:

EXCEL
=CODE(A1) // returns 97
Example 3

The CODE function takes a single argument, text, which is normally a text value. If text contains more than one character, the CODE function returns a

EXCEL
=CODE("A") // returns 65
=CODE("Apple") // returns 65
Example 4

The CODE function will handle numeric input for the numbers 0-9:

EXCEL
=CODE(1) // returns 49
Reverse CODE

To get a character for a given numeric code, you can use the CHAR function:

EXCEL
=CHAR(65) // returns "A"

See Also

CODE CHAR UNICODE UNICHAR