CODE Function in Excel – Usage with Examples

In the earlier blogs, we did the usage of the CHAR Function. The CHAR Function gives the character corresponding to a number. In this blog, will implement the CODE Function in Excel. So let’s get started.

When to Use CODE Function in Excel?

The CODE Function in excel converts the first character of a text string into its numerical code. The Windows operating system works as per the ASCI character set and Mac operating system works in the Macintosh character set.

The CODE function is categorized under the text functions of excel.

Syntax and Arguements

=CODE(text)

The following point would explain to you the required function input of the CODE formula.

  • text – this can be a reference to a cell or a range of cells containing a text string. A text string refers to the combination of characters. We can also pass the text string directly in double quotes as the function argument.
CODE Function in Excel – Usage with Examples

Examples to Learn CODE Formula

In this part of the blog, we would perform some examples to implement the CODE Function usage.

Example 1 – Basic Implementation of CODE Formula

Here, we would take the following text strings in the range A2:A11.

CODE Function in excel - raw data

Use the following CODE formula in cell B2.

=CODE(A2)

Select the range B2:B11 and press the ctrl d key to copy the formula down the range B2:B11.

CODE Function in excel result

As a result, the formula converts the textual values into the corresponding codes based on the first character of the text string.

Explanation – The numerical code for “a” and “b” is 97 and 98 respectively. The character code for “A” is 65.

Cells A5 and A6 contain “Ba” and “BCA” respectively. The first character of these text strings is “B”. Therefore, the function returns 66 as the result in cells B5 and B6.

The character code of p and q is 112 and 113 returned in cells B7 and B8.

The numerical values 10 and -10 return 49 and 45.

The character code of special character @ in cell A11 is 64.

Example 2 – Using CODE function with UPPER or LOWER Function

The UPPER and LOWER Function convert a text string into uppercase and lowercase respectively.

The character codes for uppercase and lowercase alphabets are different.

For Example, we can find the character code of the text string “Excelunlocked” by using the following formula.

=CODE("Excelunlocked")
using the CODE Function in excel

The CODE function has returned the numerical value corresponding to the first character of the text string “Excelunlocked”. This is a capital “E”, whose numerical value is 69.

Alternatively, we can also use this formula.

=CODE(UPPER("excelunlocked"))
using the CODE Function in excel part 2

The formula gives the same results.

Explanation – We have passed the text string “excelunlocked” to UPPER Function. The UPPER Function converts the letters into uppercase as”EXCELUNLOCKED” and passes it to CODE formula input. The CODE formula returns the code for the first character “E” as 69.

Points to Remember about CODE Formula

The following points about the CODE Function must be kept in mind.

  • The result of the CODE function is always a numerical value.
  • It gives a number corresponding to the first character in the text string.
  • CODE function is a reverse of CHAR Function.
  • The CODE Formula returns a #VALUE! error when we pass an empty text string as its input.

This brings us to the end of the blog.

Thank you for reading.

Leave a Comment