Excel CODE Function

Sometimes we need a number or a numeric value to represent a given character. The best example is the ASCII codes. The Excel CODE function can be used to figure out the numeric codes supplied to the CHAR function. Example CODE (“a”) returns the numeric code 97.




text– The text (or) character for which you want the numeric code.

How does this function work?

The text argument contains the text string for which a numeric code has to be generated. The CODE function returns the code for the first character in a text string. The numeric code is returned based on the character set used by your computer.

Note on CODE formula examples

Excel CODE function can also be combined with other functions in Excel to perform different and unique operations examples include,

  1. To remove unwanted characters by using it along with the SUBSTITUTE function.
  2. To abbreviate names or words that contain capital letters by using it along with TEXTJOIN  function.


      1. Let us take an example of different text strings (or) the characters as shown below in the figure and find out the result for each case. The result is as shown in the spreadsheet below. The ASCII value of ‘B’ is returned as shown.

Figure 1. The ASCII value of ‘B’ is returned

      2. If a string text is specified then the Excel CODE function returns the code number for the first character.

Figure 2. The ASCII value of ‘B’ is returned since it is the first character in the string

      3. It also returns code values for the special character such as ‘#’, ‘*’ etc., as shown below.

Figure 3. The code value of ‘#’ is returned

Our customers love us!
“The expert was absolutely amazing and stuck with me the whole way through. They were polite, patient, seemed to want to genuinely help me and provided a solution that I would never have managed otherwise. I could not be more thankful for their support and solution. Thank you!” - - Chris T, in California

Leave a Comment