CODE

    Text

    Returns the numeric ASCII code for the first character in a text string.

    Translations
    EnglishCODE
    FrenchCODE
    SpanishCODIGO
    GermanCODE
    ItalianCODICE
    PortugueseCÓDIGO
    DutchCODE
    PolishKOD
    RussianКОДСИМВ
    TurkishKOD
    CzechKÓD
    HungarianKÓD
    SwedishKOD
    DanishKODE
    FinnishKOODI
    Syntax
    CODE(text)

    Arguments

    • textText string
    Examples
    =CODE("A")
    65

    ASCII code for A

    =CODE("a")
    97

    ASCII code for lowercase a

    =CODE("1")
    49

    ASCII code for digit 1

    Tips & Best Practices
    • Only returns code for first character
    • Use CHAR to convert code back to character
    • Useful for sorting and validation
    Common Mistakes
    • 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
    Related Functions
    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.
    Frequently Asked Questions

    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