Excel Code Function

Character Encoding

The character encoding used by your computer depends on the operating system used.

Windows uses the ANSI character set, whereas Macintosh uses the Macintosh character set.

Therefore, the numeric codes returned by the Excel Code Function for specific characters may be different for different operating environments.
Related Functions:
CHAR function
UNICODE function

Function Description

The Excel CODE function converts the first character of a supplied text string into the associated numeric character set code used by your computer.

Note that the returned code may vary across different computer systems.

The syntax of the Code function is:

CODE( text )

Where the text argument is a text string that begins with the character that you want the code of.


Code Function Examples

The following spreadsheet shows examples of the Excel Code function, used to return the numeric code for four different characters.

Note that the results shown are from the Ansi character set (used on the Windows operating system).

 Formulas:
  A B
1 Alpha =CODE( A1 )
2 alpha =CODE( A2 )
3   =CODE( "?" )
4   =CODE( "3" )
 Results:
  A B  
1 Alpha 65   - returns the code for the character "A"
2 alpha 97   - returns the code for the character "a"
3   63
4   51

For further information and examples of the Excel Code Function, see the Microsoft Office website.