CODE Function

Returns the code number of the first character in a text value.

Category

Text

Available in

All versions, Microsoft 365

Returns

A number

Want to practice CODE in a real spreadsheet? Open a blank sheet in our Practice Sandbox and try it with live data, with the AI Excel tutor beside you. No Excel needed — just a free account.Try it free in the Sandbox

Overview

CODE is the reverse of CHAR: give it text and it tells you the code of the first character.

It's a detective tool — when two cells look identical but don't match, CODE can reveal a hidden character such as 160 (a non-breaking space).

Syntax

=CODE(text) Explain

Arguments

ArgumentRequired?What it does
textYesThe text whose first character you want the code for.

Examples

Example 1 — First-character codes

Capital and lowercase letters have different codes.

B2fx=CODE(A2)
AB
1TextCode
2A65
3apple97
4Zebra90
=CODE(A2) Explain

Example 2 — What's that last character?

Check the final character of a stubborn cell.

=CODE(RIGHT(A2)) Explain

32 is a normal space, 160 a non-breaking space and 10 a line break.

Common mistakes

  • Only the first character. CODE ignores everything after the first character. Combine it with MID to inspect others.

Notes

Kyle Stott

Author

Kyle Stott

Certified Microsoft Excel Expert

Kyle has worked professionally with Microsoft Excel for over a decade and has consulted on and taught Excel best practices to over 400 companies across 30+ countries.