CODE Function in Excel: Character Code of the First Letter

CODE Function in Excel: Character Code of the First Letter featured illustration

📎 This article includes 1 downloadable practice file ↓

⏱ 2 min readUpdated 28 September 2026

TextLevel: IntermediateAvailable in: Excel 2007+

In this article
  1. Syntax
  2. Examples
  3. Example 1
  4. CODE in practice
  5. Where you will use it
  6. Worked example
  7. Mistakes people make
  8. Related functions
  9. Continue learning

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.

Advertisement

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

TextFormulaResult
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

MistakeWhat to do instead
Only the first character is checkedUse CODE(MID(A2,n,1)) for other positions
Unicode charactersUse UNICODE for symbols outside ANSI

CHAR · UNICODE · CLEAN · TRIM

📚 Part of the free Excel course: Beginner → Expert · Try it in the Formula Lab or ask the AI Helper.

⚡ Interactive Practice Lab & Formula Tester:

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.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong