Excel function

CODEfunction

Returns the character code of the first character of a text.

All versions
=CODE(A2)
A
B
1
2
3
4
5
6
7
8

Click a cell in the table to change text. Click " Excel". There is a space in front, so the result is 32, not 69 (E). Try breaking it on purpose to see the errors.

Result

65

text
A2You can also click a cell in the table

The cell containing the text whose code you want. Only the first character counts.

What is the CODE function?

=CODE(text)

CODE tells you the character code of the first character of a text. Characters that look alike have different codes: capital A is 65 and lowercase a is 97.

It is useful for finding invisible characters: a hidden leading space gives 32 and a line break gives 10. According to Microsoft, the result follows your computer's character set, so characters at 128 and above are left out of the example above.

Arguments

text
The text whose code you want. Only the first character counts. Empty text gives #VALUE!.

CODE examples

  1. Example 1. Example from Microsoft

    =CODE("A")

    65. CODE("!") is 33.

  2. Example 2. Code of the second character

    =CODE(MID(A2, 2, 1))

    Take the character you want with MID, then check it with CODE.

  3. Example 3. Find a hidden space

    =CODE(A2)=32

    TRUE if the first character is a space. TRIM can remove it.

Common mistakes

FAQ

What is the opposite function?
CHAR. CHAR(65) is A.
Compare case-sensitively?
EXACT compares whole texts, case included.