Contents
Congratulations! You made it to the end of the first week of the marathon 30 Excel functions in 30 days, having studied the function yesterday FIXED (FIXED). Today we’re going to relax a bit and take a look at a function that doesn’t have many use cases – the function CODE (CODE). It can work together with other functions in long and complex formulas, but today we will focus on what it can do on its own in the simplest cases.
So, let’s deal with the reference information on the function CODE (CODE) and consider the options for its use in Excel. If you have tips or examples of use, please share them in the comments.
Function 07: CODE
Function CODE (CODE) returns the numeric code of the first character of a text string. For Windows, this will be the code from the table ANSI, and for Macintosh – the code from the symbol table Macintosh.
How can you use the CODE function?
Function CODE (CODESYMB) allows you to find the answer to the following questions:
- What is the hidden character at the end of the imported text?
- How can I enter a special character in a cell?
Syntax CODE
Function CODE (CODE) has the following syntax:
CODE(text)
КОДСИМВ(текст)
- text (text) is a text string whose first character code you want to get.
Traps CODE (CODE)
The results returned by the function may vary on different operating systems. The ASCII character codes (32 to 126) mostly correspond to the characters on your keyboard. However, the characters for higher numbers (from 129 to 254) may differ.
Text copied from a website sometimes contains hidden characters. Function CODE (CODE) can be used to determine what these characters are. For example, cell B3 contains a text string that contains the word “test‘ is 4 characters in total. In cell C3, the function LEN (DLSTR) calculated that there are 3 characters in cell B5.
To determine the code of the last character, you can use the function RIGHT (RIGHT) to extract the last character of the string. Then apply the function CODE (CODE) to get the code for that character.
=CODE(RIGHT(B3,1))
=КОДСИМВ(ПРАВСИМВ(B3;1))
In cell D3, you can see that the last character of the string has the code 160, which corresponds to the non-breaking space that is used on websites.
Example 2: Finding the character code
To insert special characters in an Excel spreadsheet, you can use the command Symbol (Symbols) tab Insertion (Insert). For example, you can insert a degree symbol ° or copyright symbol ©.
Once a symbol has been inserted, its code can be determined using the function CODE (KODSIMV):
=IF(C3="","",CODE(RIGHT(C3,1)))
=ЕСЛИ(C3="";"";КОДСИМВ(ПРАВСИМВ(C3;1)))
Now that you know the code, you can insert a character using the numeric keypad (not the numbers above the alphabetic keypad). Copyright symbol code − 169. Follow the steps below to enter this character into a cell.
Entering on the numeric keypad
- Press the key Alt.
- On the numeric keypad, enter the 4-digit code (if necessary, add the missing zeros): 0169.
- Release the key Altto make the character appear in the cell. If necessary, press Enter.
Keyboard input without number pad
In laptops, it happens that in order to use the functionality of the numeric keypad, you need to additionally press special keys. I recommend checking this with the user manual for your laptop. Here’s how it works on my Dell laptop:
- Press a key Fn and the F4, to turn on NumLock.
- Find the number pad located on the keys of the alphabetic keyboard. On my keyboard: D=1, K = 2 and so on.
- Click Alt+Fn and, using the numeric keypad, enter the 4-digit character code (adding zeros if necessary): 0169.
- Let go Alt+Fnto make the copyright symbol appear in the cell. If necessary, press Enter.
- When done, click again Fn + F4to disable NumLock.