CODE Function

CODE Function

CODE Function

Returns the numeric code for the first character in a text string.

ExcelClash Team
PUBLISHED

Summary

The Excel CODE function returns the numeric code for the first character in a text string. For example, =CODE("A") returns 65.

CODE is useful when you need to identify a character that is hard to notice, such as a leading space, a line break, or another unexpected symbol. It only looks at the first character, so it is often used as a diagnostic tool rather than a display function.

Purpose

Convert a character to its code

Returns the numeric code for the first character in the text.

Return Value

A whole number

Returns the code for the first character only.

Syntax

=CODE(text)

text is the string or cell reference you want to inspect. CODE reads only the first character and ignores the rest of the string.

Arguments

  • text - [Required] The text string or cell reference whose first character you want to identify.

CODE vs Other Functions

CODE and CHAR work as opposites. CODE gives you the number for a character, and CHAR turns that number back into the character. CLEAN, TRIM, and SUBSTITUTE often appear in the next step, after CODE helps identify the problem.

Function Main Role Use When
CODE Character to code You want to identify the first character numerically
CHAR Code to character You want to recreate a character from its code
TRIM Remove extra spaces You suspect spacing issues
SUBSTITUTE Replace a chosen character You know which character should be removed or changed

Using CODE

CODE is often used when a value looks correct on screen but still behaves differently in a lookup or comparison. If the first character is a hidden line break or an extra space, CODE can reveal it.

It is also useful when case matters. Uppercase and lowercase letters have different codes, so CODE can show that "A" and "a" are not treated the same.

  • Use CODE when a hidden first character may be causing a problem.
  • Use CODE with CHAR and SUBSTITUTE when you need to identify and then remove a specific character.
  • Use CODE with MID if the character you need to inspect is not the first one.

Example 1 - Checking a Single Character

This is the direct use of CODE. The first character is converted into its numeric code.

=CODE("A") // 65
=CODE("a") // 97
=CODE("1") // 49
Check Answer
Challenge #1
Target: Sheet1!F1
Basic Character Check

In cell F1, use CODE to find the number for the letter in B1. B1 contains "A". Expected result: 65.

Example 2 - Spotting the Difference Between Cases

Uppercase and lowercase versions of the same letter do not share the same code. That makes CODE useful when a column should follow one case rule.

=CODE("A") // 65
=CODE("a") // 97
Check Answer
Challenge #2
Target: Sheet1!F2
Lowercase vs Uppercase

In cell F2, use CODE on B2 to find the number for "a" (lowercase). Notice it is different from "A". Expected: 97.

Example 3 - Finding a Hidden Character

If a cell begins with an invisible character, CODE can reveal it. A result of 10 often means a line break, and 32 means a regular space.

=CODE(B3)
// If B3 starts with a line break, the result is 10
Check Answer
Challenge #3
Target: Sheet1!F3
Find the Hidden Character

In cell F3, use CODE on B3 to reveal the code of the first hidden character. Expected: 10.

Example 4 - Comparing Against a Target in Another Cell

CODE can also support simple rules. In this example, the formula checks whether the code of the first character meets a minimum value stored in another cell.

=IF(CODE(B4)>=C4, "Pass", "Fail")
Check Answer
Challenge #4
Target: Sheet1!F4
Pass or Fail Check

In cell F4, use CODE to check if the letter in B4 meets the minimum code stored in C4. Formula: =IF(CODE(B4)>=C4,"Pass","Fail").

If the character you need is not at the start of the string, combine CODE with MID. For example, =CODE(MID(A1,3,1)) checks the third character instead of the first.

Conclusion Recap

  • Summary: CODE returns the code for the first character in a text string.
  • Syntax: =CODE(text).
  • Key point: CODE checks only the first character unless you pair it with another function like MID.
  • Practical usage: Hidden-character checks, case checks, and text diagnostics.
  • Best pattern: Use CODE to identify a problem character, then use CHAR and SUBSTITUTE to clean it.
Tactical Arena
Select Scenario:
Share CODE Function!

Tell your friends about this post

Discussion

ExcelClash is an interactive platform designed to level up your Excel skills through real-world exercises and challenges. Sharpen your logic, solve real spreadsheet problems, and learn faster.

© 2026 ExcelClash, Inc. All rights reserved.