How to Use CODE Function in Excel (5 Examples)

Get FREE Advanced Excel Exercises with Solutions!

The CODE function, an Excel Text function returns a numeric code for the first character of a text string. The returned numeric code is based on the character set used by the operating system of the computer. Windows operating systems use the ASCII or ANSI character set.

Excel CODE function

In this above image a general overview of the Excel CODE function is given. Throughout the article, we will learn more details and different applications of the function.


Introduction to The CODE Function

❑ Objective

Excel CODE function returns a numeric code for the first character in a text string, in the character set used by your computer.

❑ Syntax

CODE(text)

syntax

❑ Argument Explanation

Argument Required/Optional Explanation
text Required Any text string, a code will be returned for the first character of the text string

❑ Output

A numeric number will be returned for the first character of the input text string. In general, the number returned by CODE represents the ASCII decimal code for a character. The CODE function was developed to operate in an ASCII/ANSI domain, and it only knows how to map characters to integers 0-255.

❑ Version

It was introduced in Excel 2000 and is available in all versions after that.


How to Use The CODE Function in Excel: 5 Examples

1. Get The ANSI Code of Alphabet

You can use the CODE function to get the ANSI code for different alphabets. Suppose you have different alphabets in a list of your Excel dataset and you want to know the corresponding code.

➤ Type the following formula in an empty cell (C6),

=CODE(B6)

The formula will return the code of the alphabet of cell B6,

Excel CODE function

➤ Press ENTER and you’ll get the code in cell C6 of the alphabet of cell B6.

output

To get the code of all of the alphabets of your dataset,

➤ Drag cell C6 to the end of your dataset.

Excel CODE function

If you notice, you will see that uppercase and lowercase of the same alphabet have different codes.


2. ANSI Code of Numerical Digits and Symbols

You can also get ANSI codes of different numerical digits and symbols using the CODE function. Suppose in this time you have a list of different digits and mathematical signs in your dataset. To get the code of these characters,

➤ Type the following formula in cell C6,

=CODE(B6)

The formula will return the code in cell C6 of the character of cell B6.

After that,

➤ Press ENTER and drag cell C6 to the end of your dataset.

As a result, you will get the codes for all of the numerical digits and signs of your dataset.

Excel CODE function

Remember that, the CODE function only returns the code of the first character of the input text strings. So, if the input number, text, or sign has multiple digits or characters the function will return a code only for the first digit or character. You will get a clear idea of that from the next image.

Explanation


3. CODE Function for Word or Sentence

For a word or sentence, the CODE function will return the code of the first character of the word or sentence. Let’s say, you have a dataset where you have a list of words and sentences. Now,

➤ Type the following formula in an empty cell C6,

=CODE(B6)

The formula will return the code for the first character of cell B6 in cell C6.

Excel CODE function

After that,

➤ Press ENTER

As a result, you will get the code of the first character of the text of cell B6 in cell C6.

output

At last,

➤ Drag cell C6 to the end of your dataset to get the code of the first character of all of the words or sentences of your dataset.

result


4. CODE Function with Other Functions

You can use the CODE function with other functions to get different desired results. Suppose you want to get the code for the uppercase of the text of cell B6. In this, you can use the UPPER function with the CODE function to get your desired result.

➤ Type the following formula,

=CODE(UPPER(B6))

Here, the UPPER function will convert the text of B6 into uppercased and then the CODE function will return the code for the first character of the converted text.

Excel CODE function

➤ Press ENTER

As a result, you will get the code for the uppercase of the first character of the input text.

UPPER

In a similar way, you can use other functions with the CODE function based on your needs. In the image below I’ve shown some such examples.

Examples


5. Text Input in The CODE Function

Instead of referring to a cell, you can input the text directly in the CODE function, though the text must be inserted between double quotation marks. To get the code for the alphabet A,

➤ Type the following formula

=CODE("A")

Here, the formula will give a code for the alphabet between the double quotation marks.

Excel CODE function

➤ Press ENTER and you’ll get the code for A

output

In a similar way, you can get the code for the first character of a text, number, or symbol.

Remember that at this time you need to insert the formula for all of the texts separately. You can’t drag the formula cell to apply the formula for other inputs when you are inserting the text directly into a formula.

Excel CODE function


💡 Things to Remember When Using The CODE Function

📌 When the text arguments left empty, the formula shows #VALUE! Error.

📌 The CODE function is inverse of the CHAR function. The CHAR function gives the character of the corresponding code.

CHAR vs CODE

📌 You may get a different output if you use any other operating system such as Linux or macOS.

📌 The CODE function only returns code for specific 255 characters of ASCII. If you need the code of any other characters you can use the UNICODE function.


📂 Download Practice Workbook


Conclusion

I hope now you know the basics of the Excel CODE function and will be able to use the function for your needs. If you have any confusion, feel free to leave a comment.


<< Go Back to Excel Functions | Learn Excel

What is ExcelDemy?

ExcelDemy - Learn Excel & Get Excel Solutions Center provides online Excel training , Excel consultancy services , free Excel tutorials, free support , and free Excel Templates for Excel professionals and businesses. Feel free to contact us with your Excel problems.
Prantick Bala
Prantick Bala

PRANTICK BALA is a marine engineer who loves exploring Excel and VBA programming. Programming, to him, is a time-saving tool for efficiently managing data, files, and internet tasks. He is proficient in Rhino3D, Maxsurf, C++, MS Office, AutoCAD, Excel, and VBA and goes beyond the basics. Armed with a B.Sc in Naval Architecture & Marine Engineering from BUET, he has transitioned into the role of a content developer. Beyond his work, find him immersed in books, exploring new... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo