Excel CHAR and CODE Functions
last modified October 5, 2026
The CHAR and CODE functions are essential text
functions in Excel that work with character encoding. CHAR
returns the character for a given numeric code, while CODE does
the reverse and returns the code of the first character in a string. On
Windows, both functions use the ANSI character set (Windows-1252), which
extends ASCII with accented letters, currency symbols, and typographic
characters. This tutorial provides a comprehensive guide to using these
functions with detailed examples. You'll learn their syntax, practical
applications, and advanced techniques.
CHAR and CODE Function Basics
The CHAR function returns the character specified by a number
from 1 to 255. The CODE function returns the numeric code for the
first character of a text string. Together they let you move between codes and
characters in either direction.
| Function | Description | Syntax |
|---|---|---|
| CHAR | Returns the character for a code from 1 to 255 | =CHAR(number) |
| CODE | Returns the code of the first character of a text string | =CODE(text) |
This table shows the basic characteristics of both functions. CHAR
takes a number (1-255) and returns the corresponding character. CODE
takes a text string and returns the code of its first character. A non-integer
number is truncated toward zero, so =CHAR(65.9) returns
A just like =CHAR(65).
| Argument | Meaning |
|---|---|
| number (CHAR) | An integer from 1 to 255. Values below 1 or above 255 return
#VALUE!. |
| text (CODE) | The text whose first character you want to inspect. An empty string
returns #VALUE!. |
CHAR and CODE are inverses of each other:
=CODE(CHAR(65)) returns 65, and =CHAR(CODE("A"))
returns A. This pairing makes it easy to verify a code or to build
text from numeric data.
=CODE(CHAR(65)) ' 65
=CHAR(CODE("A")) ' A
ANSI and Unicode
On Windows, CHAR and CODE use the ANSI character set
(Windows-1252), not the older 7-bit ASCII set. The two sets agree on codes 0-127,
but codes 128-159 hold extra symbols in Windows-1252, such as the euro sign at
code 128 and the trademark sign at code 153. This is why CODE can
return values above 127.
Modern Excel also provides the Unicode counterparts UNICHAR and
UNICODE. UNICHAR accepts a code point from 1 to
1,114,111 and returns the matching Unicode character, while UNICODE
returns the code point of the first character. Use them when you need characters
outside the 255-character ANSI set, such as emoji or non-Latin scripts.
| Function | Description | Syntax |
|---|---|---|
| UNICHAR | Returns the Unicode character for a code point (1-1,114,111) | =UNICHAR(number) |
| UNICODE | Returns the Unicode code point of the first character | =UNICODE(text) |
=CHAR(128) ' euro sign, Windows-1252
=UNICHAR(8364) ' euro sign, Unicode code point
=UNICODE("A") ' 65
=UNICHAR(128) returns a control character rather than the euro
sign, because Unicode code point 128 is different from ANSI code 128. The
UNICODE function returns 8364 for the euro sign, the code point
that CHAR cannot express.
Common Character Codes
The following table lists codes that are used most often in formulas. The character column shows what each code produces on a Windows system.
| Code | Character | Name |
|---|---|---|
| 9 | Tab | Horizontal tab |
| 10 | Line feed | Line break inside a cell |
| 13 | Carriage return | Carriage return |
| 32 | Space | Space |
| 34 | " | Double quote |
| 38 | & | Ampersand |
| 39 | ' | Apostrophe |
| 60 | < | Less-than sign |
| 62 | > | Greater-than sign |
| 64 | @ | At sign |
| 65 | A | Uppercase A |
| 90 | Z | Uppercase Z |
| 97 | a | Lowercase a |
| 122 | z | Lowercase z |
| 128 | € | Euro sign (Windows-1252) |
| 149 | • | Bullet (Windows-1252) |
| 153 | ™ | Trademark sign (Windows-1252) |
| 160 | Non-breaking space | |
| 176 | ° | Degree sign |
| 177 | ± | Plus-minus sign |
Codes 1-31 are control characters. They rarely print, but CHAR(10)
and CHAR(13) are useful for line breaks, and CHAR(9)
inserts a tab. CHAR(160) looks like a space but is not trimmed by
the TRIM function, which is a common source of lookup failures.
Basic CHAR Example
This example demonstrates the simplest use of the CHAR function to return a common character.
=CHAR(65)
This formula returns the uppercase letter "A", which has code 65.
The CHAR function is useful for generating specific characters
when you know their codes.
Basic CODE Example
This example shows how to use the CODE function to find the code for a character.
=CODE("A")
This formula returns 65, the code for uppercase "A". CODE only
looks at the first character of the input string, making it useful for
analyzing single characters.
Generating Special Characters
CHAR is often used to insert special characters that aren't
readily available on keyboards. This example shows how to create line breaks
in cells.
| A | B |
|---|---|
| First line | |
| Second line | |
| =A1 & CHAR(10) & A2 |
The table demonstrates combining text with CHAR(10) to create a line break. Note that you must enable "Wrap Text" for the cell to display properly.
="Line 1" & CHAR(10) & "Line 2"
This formula combines two text strings with a line break character (code 10)
between them. The result displays as two lines in one cell when wrap text
is enabled. The same idea works with CHAR(13), the carriage
return, which Windows programs often place before the line feed.
Analyzing Character Codes
CODE can help analyze and compare characters. This example shows
how to check whether a character is uppercase.
| A | B |
|---|---|
| M | |
| m | |
| =CODE(A1) & " vs " & CODE(A2) |
The table compares the codes for uppercase and lowercase "M". Uppercase M is
77 and lowercase m is 109, so this demonstrates how CODE reveals
case differences. For letters of the alphabet, the lowercase code is always
32 higher than the uppercase code.
=IF(AND(CODE(A1)>=65, CODE(A1)<=90), "Uppercase", "Not uppercase")
This formula checks whether the character in A1 is uppercase by verifying that its code falls between 65 (A) and 90 (Z). It returns "Uppercase" when true.
Creating Custom Formats
CHAR can help create custom text formats by inserting special
characters. This example shows how to add bullet points.
| A | B |
|---|---|
| Item 1 | |
| Item 2 | |
| =CHAR(149) & " " & A1 & CHAR(10) & CHAR(149) & " " & A2 |
The table demonstrates creating a bulleted list using CHAR(149) for bullet points and CHAR(10) for line breaks between items. Code 149 is the bullet character in the Windows-1252 set.
=CHAR(149) & " First item" & CHAR(10) & CHAR(149) & " Second item"
This formula creates a two-item bulleted list in one cell. CHAR(149) produces a bullet point, and CHAR(10) adds a line break between the items. Wrap text must be enabled for the breaks to appear.
Generating Alphabet Sequences
CHAR can generate alphabet sequences using the codes for A-Z
(65-90) and a-z (97-122). This example creates an uppercase alphabet sequence.
| A | B |
|---|---|
| 1 | |
| 2 | |
| 3 | |
| =CHAR(64+A1) & "-" & CHAR(64+A2) & "-" & CHAR(64+A3) |
The table shows how to convert numbers to corresponding letters by adding 64,
the offset that maps 1 to A, and using CHAR. This creates a letter
sequence from numbers.
=CHAR(64+ROW())
This formula generates letters corresponding to row numbers (A in row 1, B in row 2, and so on). It is useful for creating dynamic column headers or labels. Note that the pattern only produces letters while the row number stays between 1 and 26.
Cleaning Non-Printable Characters
CODE can identify and clean non-printable characters in imported
data. Control characters have codes below 32 and often arrive from other
systems. This example shows how to detect them.
| A | B |
|---|---|
| ="Data" & CHAR(9) | =CODE(RIGHT(A1,1)) |
Cell A1 builds the text "Data" followed by a tab character, and B1 returns the code of its last character. The result is 9, confirming that the string ends with a tab.
=IF(CODE(RIGHT(A1,1))<32, "Contains control character", "Clean")
This formula checks whether the last character in A1 has a code below 32,
which means it is a control character. It returns a warning message when one
is found and "Clean" otherwise. Remember that RIGHT extracts the
last character before CODE inspects it.
Creating Password Complexity Checks
CODE can help enforce password complexity by checking for mixed
character types. This example verifies that a password contains at least one
uppercase letter.
| A | B |
|---|---|
| PassWord1 | =SUMPRODUCT(--(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))>=65), --(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))<=90))>0 |
The table shows a formula that examines each character's code and counts how many fall in the uppercase range. It returns TRUE because "PassWord1" contains uppercase letters.
=SUMPRODUCT(--(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))>=65),
--(CODE(MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))<=90))>0
This formula returns TRUE if the text in A1 contains at least one uppercase
letter (codes 65-90). MID splits the string into single characters,
CODE converts each one to its code, and SUMPRODUCT
adds up the matches. It demonstrates advanced use of CODE for text
analysis.
CHAR and CODE Errors and Troubleshooting
| Cause | Symptom | Fix |
|---|---|---|
| Code below 1 or above 255 passed to CHAR | #VALUE! error | Use a code from 1 to 255, or switch to UNICHAR for larger code points |
| Empty string or empty cell passed to CODE | #VALUE! error | Test with LEN first, for example =IF(LEN(A1)>0, CODE(A1), "") |
| CODE reads only the first character | Unexpected code for a multi-character string | Extract the wanted character with MID or RIGHT before calling CODE |
| Character is outside the ANSI set | CODE may return 63 (question mark) | Use UNICODE and UNICHAR for characters above code 255 |
| Non-integer code passed to CHAR | Unexpected character | The number is truncated toward zero, so CHAR(65.9) is CHAR(65) |
| CHAR(10) does not show a line break | Text stays on one line | Enable Wrap Text for the cell |
The CHAR and CODE functions are powerful tools for
working with character data in Excel. CHAR turns codes into
characters for line breaks, bullets, and symbols, while CODE
reveals the code behind any character for cleaning and validation. Together
they form the bridge between text and numbers. For characters beyond the ANSI
range, reach for UNICHAR and UNICODE. Mastering these
functions will enhance your ability to clean, format, and analyze text data
efficiently.
Author
List all Excel Formulas.