How to use CODE Function in Excel?

The CODE function in Microsoft Excel is a very handy function in case we need to get the ANSI or ASCII code for a character/letter/symbol/number etc. This tutorial will introduce you to the CODE function and also will show you some of the best uses of this function in Excel.

This Content Covers:

  1. What is CODE Function in Excel?
  2. Syntax, Purpose, and Arguments of CODE Function
  3. How to use/access the CODE Function in Excel?
    • From Formula Tab
    • Typing Manually
  4. Different uses of CODE Function in Excel
    • Getting the ANSI Code of Alphabet
    • Getting the ANSI Code of Numerical Digits
    • Getting the ANSI Code of Symbols
    • CODE Function with Word or Sentence
    • CODE Function with Other Functions

 

1. What is CODE Function in Excel?

The CODE function in Microsoft Excel is a built-in function that is used to determine the ASCII or ANSI code for the selected character in a supplied dataset. After accepting any type of character as input, the method returns the numeric code, including letters, numbers, symbols, etc. It finds out the code for the first character only.

2. Syntax, Purpose, and Arguments of CODE Function

Syntax: =CODE(text)

Purpose: The purpose of CODE function is to Get the code for a character

Arguments: There is only one argument for CODE function,

text- The text for which you are looking for a numerical code.

3. How to use/access the CODE Function in Excel?

There are two ways you can use or access the CODE function. You can either use the function from Formula tab or you can type it directly inside a cell.

3.1 From Formula Tab

Step 1: Select a cell where you want to use the CODE function and then go to Formulas tab. Select Text option and click on CODE from the drop-down list.

CODE Function

Step 2: A Function Arguments dialogue box will open. Insert or type the text you want to get the code of inside Text box and press OK.

CODE Function

Step 3: This will return you a code value for the first character of the input text.

CODE Function

3.2 Typing Manually

Step 1: Select a cell and start typing the code with =C, you will see the CODE function in the drop-down list. Double click on it and type the text inside then press Enter key.

CODE Function

4. Different uses of CODE Function in Excel

4.1 Getting the ANSI Code of Alphabet

Step 1: Select cell B3 and insert the CODE function in it.

CODE Function

Step 2: Press Enter key to get the result.

CODE Function

Step 3: Drag the fill-handle down to B7 to get ANSI code for all of these input alphabets. Here you can notice that letter “D” and “d” have different CODE though they are the same letter. Which means ANSI code for upper- case and lower-case letters are different. We can see the difference in case of “Z” and “z” too.

CODE Function

4.2 Getting the ANSI Code of Numerical Digits

Step 1: Enter the CODE formula in B3 like before and press Enter key.

CODE Function

Step 2: Drag B3 down to B7. In this example, we have used the CODE function to get ANSI code of some numerical values. Now look at the code value of 9 and 99, both of them has same code value. Though we had 99 in A5 cell, the CODE function only takes a string’s first letter or digit. So, in this case the CODE function took 9 from 99 and returned its code value.

CODE Function

4.3 Getting the ANSI Code of Symbols

Step 1: Use the CODE function here in the same way to get the ANSI code for these symbols.

CODE Function

4.4 CODE Function with Word or Sentence

Step 1: Use the CODE function in B3, press Enter key and drag the fill handle down.

CODE Function

Step 2: As we have seen in the first and second example, the CODE function only takes the first letter or digit or symbol from a string and the code value for upper- case and lower-case letters are different. So, although we used words and sentences here, the CODE function only took the first letter as its input and returned the ANSI code for that letter or alphabet. We also see difference in code value of same letters (“M”, ”m”/”O”, ”o”) for being upper and lower case.

CODE Function

4.5 CODE Function with Other Functions

In the previous example we saw two different values for the same word “Muffin” and “muffin” because of the case difference of the first letter “M” and “m”. By using the UPPER and LOWER function with CODE function, we can get the ANSI code of a lower-case letter from upper-case letter/word/sentence, and we can get code of lower-case letter from upper-case letter/word/sentence.

CODE Function

Step 1: Select cell B6 and insert this combined function of CODE and LOWER functions in that cell. Then press Enter key to get the result.

CODE Function

Step 2: Select cell B7 and insert this combined function of CODE and UPPER functions in that cell.

CODE Function

Step 3: Hit the Enter key. Here we can see that though we had an upper-case “M” in cell A6, the formula in B6 has returned the code of lower- case “m” because of using LOWER function with CODE function in that cell. The same thing happened in B7 too, by using the UPPER function with CODE function we got the code of upper- case “M” from a word which had a lower- case “m” as the first letter.

CODE Function

For ready-to-use Dashboard Templates:

  1. Financial Dashboards
  2. Sales Dashboards
  3. HR Dashboards
  4. Data Visualization Charts

Leave a Comment

Your email address will not be published. Required fields are marked *

Categories