
📎 This article includes 1 downloadable practice file ↓
In this article
CODE returns the number of the first character. It is the detective tool for “invisible” characters that break lookups: a non-breaking space shows up as 160, not 32.
Syntax
=CODE(text)
| Argument | What it means |
|---|---|
text |
Text; only the first character counts. |
Examples
Example 1
=CODE(RIGHT(A2))
Reveal what the last character of a clean-looking cell really is.
CODE in practice
Where you will use it
- Find the hidden character breaking a lookup
- Check if text starts with a letter or digit
- Debug imported data
Worked example
| Text | Formula | Result |
|---|---|---|
| A | =CODE(A2) | 65 |
| a | =CODE(A3) | 97 |
| ₹ | =CODE(A4) | 63 |
Results calculated in Excel. ₹ is outside the old ANSI character set, so CODE returns 63 (the code for ?). Use UNICODE for it: 8377.
Mistakes people make
| Mistake | What to do instead |
|---|---|
| Only the first character is checked | Use CODE(MID(A2,n,1)) for other positions |
| Unicode characters | Use UNICODE for symbols outside ANSI |
Related functions
📚 Part of the free Excel course: Beginner → Expert · Try it in the Formula Lab or ask the AI Helper.
Test formulas dynamically in our web formula laboratory or download the companion Excel workbook.
📎 Practice files for this article
- 📗Practice workbook: Text & cleaning24 tasks on realistic sales data — type your formula, the Check column turns green when it is right. Answers sheet included.⬇ XLSX · 35 KB
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Atul (AJ) builds office-automation and local-first AI tools as Atulya AI, and works with Excel, SAP and Oracle EPM every day. He writes about the shortcuts, macros and automations that actually save time — plus the occasional wacky fact. Videos on YouTube: Lazy Automator AI (@LazyAutomatorAI).
More posts by Atul →Build this skill next
This page is a quick function reference. Use it for syntax, then practise the function in a broader workflow.
Stuck on a step? Ask a question and the AI answers using this article.