Spreadsheet Practice

CODE function

CODE returns the numeric code of the first character in a text string. It's a diagnostic tool: when two cells look identical but won't match, CODE reveals hidden characters such as a nonbreaking space (160), a tab (9) or a line break (10).

Available in
Every current version
Category
Text functions
Returns
A number: the code of the first character.

Syntax

=CODE(text)

ArgumentRequired?What it is
textRequiredThe text whose first character you want to identify.

Examples

Each result below is calculated from the sample sheet by our formula engine, the same one that grades the practice.

CellFormulaResultWhat it shows
B2=CODE(A2)65Capital A is code 65
B3=CODE(A3)97Lowercase a is 97, so case changes the code
B4=CODE(A4)32A leading space shows up as 32

Try it live

This is the sample sheet. Change any number or text, or edit a formula, and the results update.

Show the sample data as a table
TextResult
Apple65
apple97
Pear32

Practice CODE

Graded instantly, then re-checked on changed data.

Spot hidden characters

Some SKUs start with a hidden space or tab. In B2, return the code of the first character of the SKU in A2, so the odd ones stand out. Fill down to B6.

Common mistakes

What you seeWhy, and how to fix it
#VALUE!The cell is empty. Guard it: =IF(A2="","",CODE(A2)).
It only checks one characterCODE ignores everything after the first character. To check another position, combine it with MID: =CODE(MID(A2,5,1)).

Tips

  • See what a trailing character really is with =CODE(RIGHT(A2)).

Questions

How do I find hidden characters in Excel?

Check the first and last characters with =CODE(LEFT(A2)) and =CODE(RIGHT(A2)). 32 is a space, 160 a nonbreaking space, 10 a line break and 9 a tab.

What is the opposite of CODE?

CHAR. =CHAR(65) returns A, and =CODE("A") returns 65.

Last reviewed October 2026. Every example result on this page is calculated live by the Spreadsheet Practice formula engine.