Excel CODE Function: Get the Numeric Code of a Character

The CODE function in Excel is used to return the numeric code of the first character in a text string. This function is especially useful when working with text data that contains hidden, special, or non-standard characters.

What Does the CODE Function Do?

The CODE function returns a numeric value that represents a character based on the character encoding used by your system. In most modern versions of Excel, this is based on the Unicode character set.

It is commonly used to:

  • Identify special or non-printable characters
  • Debug text imported from external systems
  • Work with character-based logic in formulas
  • Detect differences between visually similar characters

Syntax of the CODE Function

=CODE(text)

Arguments:

  • text – The text string or cell reference containing the character you want to evaluate.

Note: Only the first character of the text string is evaluated.

Example: Basic Usage

If cell A1 contains the letter A, the formula:

=CODE(A1)

Returns:

65

This is because the numeric code for the uppercase letter A is 65.

Finding Special or Hidden Characters

The CODE function is very helpful when text appears normal but behaves unexpectedly in formulas or comparisons.

For example, if cell A2 contains a hidden character copied from another system:

=CODE(A2)

The returned number can help you identify whether the character is a space, line break, tab, or another non-standard character.

Common Character Codes

Character CODE Result
Space 32
Line Break 10
Tab 9
A 65
a 97

Download Excel CODE Function Demo File

Get instant access to a free Excel CODE Function demo file that helps you understand how character codes work in Excel.
This file includes practical examples to identify letters, spaces, tabs, and hidden characters using the CODE() function.

  • ✔ Ready-to-use Excel template
  • ✔ Live CODE() formulas with explanations
  • ✔ Learn how to detect hidden & non-printable characters
  • ✔ Perfect for beginners and advanced Excel users


⬇ Download Excel CODE Function Demo (Free)

No sign-up required. Compatible with Excel 2016, Excel 2019, Excel 365, and Excel Online.

Using CODE with Other Functions

The CODE function is often combined with other text functions for advanced analysis.

Example: Check if a Character Is a Space

=CODE(A1)=32

This formula returns TRUE if the first character in A1 is a space.

Example: Identify Non-Printable Characters

=IF(CODE(A1)<32,"Non-printable","Printable")

This can help flag problematic characters in imported data.

Difference Between CODE and CLEAN

  • CODE identifies the numeric value of a character
  • CLEAN removes non-printable characters from text

In many cases, you might use CODE to find problematic characters and CLEAN to remove them.

Important Notes

  • Only the first character of the text string is evaluated
  • Results may vary slightly depending on character encoding
  • CODE works best for diagnostics, not text cleanup

Conclusion

The Excel CODE function is a powerful diagnostic tool for understanding and working with characters in text strings. Whether you are cleaning imported data or troubleshooting formula issues, CODE helps reveal what’s really inside your text.

Use CODE together with functions like CLEAN, TRIM, and SUBSTITUTE for complete text control in Excel.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.