|
Home > Formulas > Text > CODE and CHAR Excel CODE and CHAR Function Examples
|

The CODE function returns a numeric code for the first character in a text string. For Windows, the returned code is from the ANSI character set, and for Macintosh, the code is from the Macintosh character set
Watch this short video for examples of how to use the CODE function. There are written steps below the video.
The CODE function is in the Text Function category of Excel functions.
You can use the CODE function can help unravel mysteries in your data, such as:
The CODE function has the following arguments in its syntax:

Results could be different if you switch to a different operating system.
When you copy text from a website, it might include hidden characters. The CODE function can be used to identify what those hidden characters are
For example, there is a text string in cell B3, and only “test” is visible — 4 characters. In cell C3, the LEN function shows that there are 5 characters in cell B3.
To identify the last character’s code, you can use the RIGHT function, to return the text value of the last character. Then, use the CODE function to return the code for that character.

In cell D3, the RIGHT/CODE formula shows that the last character has the code 160, which is a non-breaking space used on websites.
To insert special characters in an Excel worksheet, you can use the Symbol command on the Ribbon’s Insert tab.
For example, you can insert a degree symbol ° or a copyright symbol ©.
After you insert a symbol, you can determine its code, by using the CODE function

To show a specific symbol on a worksheet, you can use its CODE number to:
Click the links, to go to those instructions.
The CHAR function returns a specified character, for the number entered, based on the character set used by your computer. (For Windows, the ANSI character set, and for Macintosh, the Macintosh character set.)
Watch this short video for examples of how to use the CHAR function. There are written steps below the video
The CHAR function is another one of the Excel text functions, and is the inverse of the CODE function. When you give the CHAR function a number, it returns the corresponding character from the character set.
The CHAR function can help enter special symbols or specific characters, such as:
The CHAR function has the following arguments in its syntax:

Just like the CODE function, CHAR results could be different if you switch to a different operating system.
To manually enter a line break in a cell, you can press Alt + Enter, but that doesn't work when you're entering a formula.
When combining text strings in a formula, you can use CHAR(10) — the ASCII value for the line break character.

After you create the formula, format the cell with Wrap Text, to see the line break, instead of that strange symbol between the strings.

Can you name the 19th letter of the alphabet?
With the CHAR function, you can quickly figure that out, without counting on your fingers!
The first step is to find the CODE for the first letter of the alphabet — A. You can type A in a cell, and refer to it, or type A as a text string in the function.
or

After that, you can use the CHAR function to find any other letter in the alphabet, by adding 64 to the requested number.
The formula's return value in cell C5 is the uppercase letter A.

With Excel’s AutoFill feature, you can type two numbers, and quickly create an entire series of numbers.
Unfortunately, that doesn’t work if you type a couple of letters. However, you can use the CHAR function to create a list with the entire alphabet
Use the same technique of adding 64 to the number, to get a letter of the alphabet.

If you want to enter the alphabet with the AutoFill feature, you can import your alphabet list into the Custom Lists feature.

You can create a reference chart with all the printable characters, by using the CHAR function. This chart will be a quick guide if you want to enter a symbol by typing (press Alt, and type the 4-digit code on the numeric keypad).
To see the characters for a different font, like Symbol or Wingdings, change the font in the CHAR function column.

If you copy data from a web page, it might contain special characters, such as non-breaking spaces.
On your worksheet, those special characters don't stand out, but they can cause problems. For example, if you try to use that data for a lookup, with VLOOKUP, or with INDEX and MATCH, you'll get an error result in your formula.
In the screen shot below, there is a MATCH formula in cell B8, and its result is an #N/A error.
There is a difference between the "Sweater Vest" in the lookup table (cell A5), and the "Sweater Vest" is in cell A8, which was copied from a web page.
To identify the difference, I used the CODE function in cells D5 and D8, to identify the 8th character's code number.
Fix Problem Characters with CHAR If possible, replace the non-breaking space characters with normal space characters, and the MATCH formula should work correctly.
However, in some situations, you might be able to change all of the data that contains non-breaking spaces. For example, if you copy and paste new data every day, that would add an extra step to your process.
So, if you can't fix the web data, you can modify the MATCH formula instead, to prevent errors.
In the revised formula shown below, I added the SUBSTITUTE function to replace the non-breaking space, CHAR(160), with a normal space character, CHAR(32).

In some cases, your data might have hidden characters, copied from a website, and the Excel CODE function doesn't recognize those characters.
This is usually caused by a number limitation on the CODE and CHAR functions:
Solution: For higher numbers, use the UNICODE and UNICHAR functions, shown in the next xection

To overcome the 255 code number limitation, you can use the following two functions, which were introduced in Excel 2013.
For example, in the screen shot above,
And in the screen shot below:

To show a specific symbol on a worksheet, you can use its CODE number in a keyboard shortcut.

If your keyaboard has a number keypad at the side, follow these steps:
If your laptop computer doesn't have a number keypad, you might need to press special keys to use the numeric keypad function. Check the owner’s manual, for directions.
Here’s what worked on my compact Dell laptop:
In the previous section, I said to use a 4-digit code with the keyboard shortcuts.
However, there is a special set of codes that don't need leading zeros - numbers 1 to 31.
The shortcut I use most often is Alt + 7, to insert a bullet point into a cell.
I like the triangle arrows too, but can't remember their code numbers! So, I made a printable list, to keep beside my computer. A quick look reminds me of those codes.

If you're making an Excel report at work, you probably don't need a happy face emoji anywhere on the worksheet. But if you're planning a party, or making a household chores list, a few emojis can add a touch of fun!

Another way to add emojis in Excel is with the UNICHAR function.
For example, the screen shot below, cell B3 shows the "partying face" emoji, for the code number (129395) in cell C3
Here's the formula in cell B3: =UNICHAR(C3)

To see a full list of emojis, download the Emoji Chart and List workbook. Thanks to Ken Puls from excelguru.ca, who created the Excel chart, shown below.

For a fun example of using emojis in Excel, you can download my Excel Treasure Hunt game, shown below. There's a short video in the next section, where I show how the game works.
In the Hoppy Hunt game shown below, the "win" is a rabbit emoji, and the "lose" is a kangaroo emoji. You don't want to find one of those in your garden!

In this 3-minute video, I show how to play the game, and how it works. There are formulas, conditional formatting, and a data validation drop-down list.
To use the "New Game" button, macros have to be enabled, but you can play the game without macros, if you prefer!
____________
Don't miss my monthly Excel newsletter! You'll get quick tips, article links, and a bit of fun. Add your email, and click Sign Up.
Next, when you get my reply, click the Confirm button. I add this step to protect you from spam!
Last updated: April 16, 2025 11:54 AM