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
Example 1. Example from Microsoft
=CODE("A")65. CODE("!") is 33.
Example 2. Code of the second character
=CODE(MID(A2, 2, 1))Take the character you want with MID, then check it with CODE.
Example 3. Find a hidden space
=CODE(A2)=32TRUE if the first character is a space. TRIM can remove it.
Common mistakes
Characters outside ASCII
For characters outside the ANSI range, the result depends on the computer's character set. For a Unicode number, use UNICODE: UNICODE("é") is 233.
Thinking it codes the whole text
CODE("Apple") and CODE("A") are both 65. Only the first character counts.
FAQ
- What is the opposite function?
- CHAR. CHAR(65) is A.
- Compare case-sensitively?
- EXACT compares whole texts, case included.