Back to functions
Text2026-06-131 related article

CODE Function in Excel

Return the numeric code for the first character in a text string.

Syntax

CODE(text)

Arguments

text

Required

The text value whose first character you want to inspect.

What it returns

Returns the numeric code for the first character in the supplied text.

What CODE does

CODE returns the numeric code for the first character in a text string. It is useful when you need to identify hidden characters, punctuation, or leading symbols that affect formulas.

Practical examples

Return the code for the first character

=CODE("A")

This returns 65, which is the code for uppercase A.

Diagnose a hidden leading character

=CODE(D3)

Use this when a cell looks blank or normal but still behaves unexpectedly, for example when a space character is causing an error.

Common mistakes and notes

CODE checks only the first character

If the problem character appears later in the string, CODE will not see it unless you isolate that position first.

The result depends on Excel's character set

Microsoft notes that the returned code corresponds to the character set used by your computer.

Related functions

Related articles

Deep dives, troubleshooting guides, and practical examples that use CODE.

Official documentation