CODE function
CODE gives the number behind the first character of a text string. It is useful for diagnosing odd characters that will not match or trim away.
Example
Read it as a sentence: show the code number for the letter A, which gives 65.
A
B
C
D
1
65
2
3
Syntax
CODE(text)
-
text(required) - The text; only its first character is used.
Returns: The numeric code of the first character.
What Excel actually returns
Each formula below was run in desktop Excel. The result is exactly what the cell showed, errors included.
| Formula | Excel shows | Case |
|---|---|---|
=CODE("A") | 65 | A |
=CODE("abc") | 97 | First character only |
=CODE(1) | 49 | Number |
=CODE("€") | 128 | Euro sign |
=CODE(UNICHAR(8364)) | 128 | Euro via UNICHAR |
=CODE(UNICHAR(12354)) | 63 | Character outside code page |
=CODE("") | #VALUE! | Empty text |
=CODE(Data!F1) | #VALUE! | Blank |
The Data sheet these formulas read
A cell that starts with = holds that formula.
F
1
Data
Watch out for
- Only looks at the first character.
- Use UNICODE for characters beyond the basic set.
Where it works
- Excel
- CODE is in every version of Excel from 2007 on.
- Google Sheets
- Same name, same behaviour for everyday use.
Part of Text functions. Every result on this page was measured in desktop Excel, build 16.0.20527. Last updated .