ElyxAI
formulas

How to How to Use CODE Function in Excel

Excel 2016Excel 2019Excel 365Excel Online

Learn how to use the CODE function to convert text characters into their numeric ASCII values. This function is essential for text analysis, data validation, and character manipulation tasks. You'll master extracting character codes to identify specific characters, compare text data, and automate text processing workflows in Excel.

Why This Matters

The CODE function is vital for text processing, debugging data issues, and building advanced formulas that validate or manipulate character data programmatically.

Prerequisites

  • Basic understanding of Excel formulas and cell references
  • Familiarity with the Formulas tab and function insertion

Step-by-Step Instructions

1

Open Excel and select a target cell

Launch Excel and click on any empty cell where you want the result to appear (e.g., cell C2).

2

Type the CODE function syntax

Enter the formula =CODE(text) where text is the character or cell reference containing the character you want to convert (e.g., =CODE("A") or =CODE(A1)).

3

Press Enter to execute the formula

Hit Enter to run the formula; Excel returns the numeric ASCII value for the first character of the text string.

4

Verify the result

Confirm the output displays the correct ASCII code (e.g., "A" returns 65, "a" returns 97).

5

Copy the formula to other cells if needed

Select the cell with the formula, press Ctrl+C to copy, then select a range and press Ctrl+V to apply it to multiple rows.

Alternative Methods

Use CHAR function for reverse conversion

If you need to convert ASCII codes back to characters, use =CHAR(65) to get "A". This is the inverse operation of CODE.

Combine CODE with other text functions

Nest CODE inside IF or SUMPRODUCT formulas to build advanced text validation and character analysis workflows.

Tips & Tricks

  • CODE always returns the ASCII value of the first character in a string; use MID to isolate specific characters first.
  • ASCII codes range from 0–127 for standard characters; uppercase letters are 65–90, lowercase 97–122.
  • CODE is case-sensitive: "A" (65) and "a" (97) return different values.
  • Use CODE to build data validation rules that check for specific character types in your datasets.

Pro Tips

  • Combine CODE with AGGREGATE to find all cells containing non-standard or special characters in bulk.
  • Use CODE in helper columns to identify and filter rows with specific character patterns or encoding issues.
  • Build conditional logic with CODE to automate data cleaning—e.g., flag rows where the first character is not a letter.
  • Pair CODE with COUNTIF to count how many times a specific ASCII value appears in a dataset.

Troubleshooting

Formula returns #VALUE! error

Ensure the cell contains actual text. If referencing empty cells or numbers without text format, CODE will fail. Add error handling with =IFERROR(CODE(A1),"No value").

Getting unexpected ASCII values

Remember CODE reads the first character only; if you need other positions, use =CODE(MID(A1, 2, 1)) to extract the second character, for example.

Formula not updating when cell changes

Check that automatic calculation is enabled (Formulas tab > Calculation Options > Automatic) and the file is not in manual calculation mode.

Related Excel Formulas

Frequently Asked Questions

What is the CODE function used for?
CODE converts a text character into its numeric ASCII value. It's useful for text analysis, character validation, data cleaning, and building advanced text-processing formulas that need to identify or compare characters programmatically.
What is the difference between CODE and CHAR?
CODE converts text characters to ASCII numbers (e.g., "A" → 65), while CHAR does the opposite (e.g., 65 → "A"). They are inverse functions—use CHAR to decode ASCII values back into text.
Can CODE process multiple characters at once?
No, CODE only returns the ASCII value of the first character in a string. To get codes for other positions, combine CODE with MID: =CODE(MID(text, position, 1)).
How do I find the ASCII code for special characters?
Simply enter =CODE("@") or =CODE(A1) where A1 contains the special character. Excel returns its ASCII value. Special characters, spaces, and symbols all have unique ASCII codes.
Is CODE case-sensitive?
Yes, CODE is case-sensitive. Uppercase "A" returns 65, while lowercase "a" returns 97. This is useful when you need to distinguish between case in text validation.

This was one task. ElyxAI handles hundreds.

Sign up