
The CODE function will return the ASCII value of the first character from any text string.
Contents:
Syntax
= CODE(text)
text - a cell reference or character that you wish to return the ASCII number of
Explanation
The CODE function is part of the "Text" group of functions within Excel.
This function will return the ASCII value of the first character in a given text string. ASCII, or the American Standard Code for Information Interchange, is a character encoding standard that represents text using numerical codes ranging from 0 to 127.
For characters outside this range, the CODE function will return the corresponding code from the 1252 character ANSI (American National Standards Institute) set.
The full list of ASCII codes and characters can be found here, but some of the most common ASCII codes are:
A to Z (uppercase): 65 to 90
a to z (lowercase): 97 to 122
0 to 9: 48 to 57
Space: 32
Exclamation mark (!): 33
At symbol (@): 64
Note:
- Only the left most character will be returned, anything after will be ignored.
Examples
How to Return the ASCII Number of the First Character in a Cell
In this example, we have a list of product IDs, and we want to identify the first character of each ID and its corresponding ASCII code.
We can simply drop in the CODE function to our workbook and reference the Product ID that we want to return the first character's ASCII code from.
= CODE(B3)

How to Return the ASCII Number of the Last Character in a Cell
Similarly, we can return the ASCII code of the last character in any cell by combining the CODE and the RIGHT function together.
We are using the RIGHT function to extract the last character from each cell, and then applying the CODE function to that specific character. This leaves us with the ASCII code for the last character in a cell.
= CODE(RIGHT(B3))
