CODE
Returns the numeric ASCII code for the first character in a text string.
CODE(text)Arguments
textText string
=CODE("A")ASCII code for A
=CODE("a")ASCII code for lowercase a
=CODE("1")ASCII code for digit 1
- •Only returns code for first character
- •Use CHAR to convert code back to character
- •Useful for sorting and validation
- •Confusing CODE with UNICODE - CODE returns a code based on the character set of your computer (typically the first 255 ASCII/ANSI values), while UNICODE returns the full Unicode code point, and they can disagree for certain characters
- •Applying CODE to more than a single character in a string, expecting a list back - it only ever returns the code of the very first character, silently ignoring the rest of the text
- •Using CODE on an empty cell or empty string, which raises a #VALUE! error since there's no character present to evaluate
CHARPerforms the reverse operation - converts a numeric code back into its corresponding character.UNICODEReturns the full Unicode code point of a character, a broader alternative to CODE for characters outside the basic ASCII/ANSI range.LENCounts how many characters a string contains, useful context before deciding whether CODE's single-character limitation matters.What's the difference between CODE and UNICODE?
CODE returns a code from your system's character set (roughly the first 255 values), while UNICODE returns the character's actual Unicode code point - for characters outside the basic Latin range, the two can give different results.
Does CODE work on a whole word or just one character?
Only the first character of the text - CODE("Excel") returns the code for "E" alone, ignoring the rest of the string.
Why does CODE return #VALUE!?
The input is an empty string or blank cell - CODE needs at least one character present to return a code.
Need to translate a formula using CODE?
Use our translator to convert your complete formula
