How to use the CHAR function
Use the CHAR function to convert a number to the corresponding character. This is determined by your computer's character set.
Windows | ANSI |
Macintosh | Macintosh character set |
Table of Contents
- Introduction
- Syntax
- Example
- How to convert comma delimiting numbers to a string of characters
- How to list all characters based on ANSI code
- How to identify a new line character in an Excel formula
- How to create a new line in an Excel formula
- How to show a new line in a cell (wrap text)
- How to create a tab in an Excel formula
- How to create superscript characters in an Excel formula
- Function not working
- Get Excel *.xlsx file
1. Introduction
What is ANSI code?
In the context of the CHAR function in Excel, ANSI code refers to a numerical code that corresponds to a specific character in the American National Standards Institute (ANSI) character set. In this context, ANSI codes are used to represent characters that may not be easily typed or represented using standard keyboard characters. For example, the ANSI code for a line break is 10, so the formula =CHAR(10) returns a line break character. The ANSI codes used in the CHAR function in Excel range from 1 to 255, and correspond to the characters in the ANSI character set. This includes letters, numbers, punctuation marks, and special characters.
The image above shows numbers and the corresponding characters.
2. Syntax
CHAR(text)
text | Required. The number for which you want the corresponding character. |
3. Example
The image above shows how to convert a number to a character using the CHAR function.
Formula in cell D3:
Explaining formula
The CHAR function converts a number between 1 and 255 to a corresponding character.
CHAR(B3)
becomes
CHAR(65)
and returns "A".
4. How to convert comma delimiting numbers to a string of characters
This example demonstrates a formula that converts a series of numbers to characters based on the ANSI character set. The TEXTSPLIT function is a new Excel 365 function.
Formula in cell D3:
Explaining formula
Step 1 - Split numbers using a comma as a delimiting character
The TEXTSPLIT function lets you split a string into an array across columns and rows based on delimiting characters.
TEXTSPLIT(Input_Text, col_delimiter, [row_delimiter], [Ignore_Empty])
TEXTSPLIT(B3, ",")
becomes
TEXTSPLIT("72,101,108,108,111,33", ",")
and returns
{"72","101","108","108","111","33"}.
There is no need to convert "text" numbers to regular numbers, the CHAR function accepts "text" numbers.
Step 2 - Convert numbers in array to characters
CHAR(TEXTSPLIT(B3, ","))
becomes
CHAR({"72","101","108","108","111","33"})
and returns
{"H","e","l","l","o","!"}
Step 3 - Join characters
The TEXTJOIN function allows you to combine text strings from multiple cell ranges and also use delimiting characters if you want.
TEXTJOIN(delimiter, ignore_empty, text1, [text2], ...)
TEXTJOIN(, , CHAR(TEXTSPLIT(B3, ",")))
becomes
TEXTJOIN(, , {"H","e","l","l","o","!"})
and returns "Hello!".
5. How to list all characters based on ANSI code
Number 65 to 90 correspond to A to Z. Number 97 to 122 correspond to a to z.
1 | 33 | ! | 65 | A | 97 | 129 | | 161 | 193 | Á | 225 | á | |
2 | 34 | " | 66 | B | 98 | 130 | ‚ | 162 | 194 | Â | 226 | â | |
3 | 35 | # | 67 | C | 99 | 131 | ƒ | 163 | 195 | Ã | 227 | ã | |
4 | 36 | $ | 68 | D | 100 | 132 | „ | 164 | 196 | Ä | 228 | ä | |
5 | 37 | % | 69 | E | 101 | 133 | … | 165 | 197 | Å | 229 | å | |
6 | 38 | & | 70 | F | 102 | 134 | † | 166 | 198 | Æ | 230 | æ | |
7 | 39 | ' | 71 | G | 103 | 135 | ‡ | 167 | 199 | Ç | 231 | ç | |
8 | 40 | ( | 72 | H | 104 | 136 | ˆ | 168 | 200 | È | 232 | è | |
9 | 41 | ) | 73 | I | 105 | 137 | ‰ | 169 | 201 | É | 233 | é | |
10 | 42 | * | 74 | J | 106 | 138 | Š | 170 | 202 | Ê | 234 | ê | |
11 | 43 | + | 75 | K | 107 | 139 | ‹ | 171 | 203 | Ë | 235 | ë | |
12 | 44 | , | 76 | L | 108 | 140 | Œ | 172 | 204 | Ì | 236 | ì | |
13 | 45 | - | 77 | M | 109 | 141 | | 173 | 205 | Í | 237 | í | |
14 | 46 | . | 78 | N | 110 | 142 | Ž | 174 | 206 | Î | 238 | î | |
15 | 47 | / | 79 | O | 111 | 143 | | 175 | 207 | Ï | 239 | ï | |
16 | 48 | 0 | 80 | P | 112 | 144 | | 176 | 208 | Ð | 240 | ð | |
17 | 49 | 1 | 81 | Q | 113 | 145 | ‘ | 177 | 209 | Ñ | 241 | ñ | |
18 | 50 | 2 | 82 | R | 114 | 146 | ’ | 178 | 210 | Ò | 242 | ò | |
19 | 51 | 3 | 83 | S | 115 | 147 | “ | 179 | 211 | Ó | 243 | ó | |
20 | 52 | 4 | 84 | T | 116 | 148 | ” | 180 | 212 | Ô | 244 | ô | |
21 | 53 | 5 | 85 | U | 117 | 149 | • | 181 | 213 | Õ | 245 | õ | |
22 | 54 | 6 | 86 | V | 118 | 150 | – | 182 | 214 | Ö | 246 | ö | |
23 | 55 | 7 | 87 | W | 119 | 151 | — | 183 | 215 | × | 247 | ÷ | |
24 | 56 | 8 | 88 | X | 120 | 152 | ˜ | 184 | 216 | Ø | 248 | ø | |
25 | 57 | 9 | 89 | Y | 121 | 153 | ™ | 185 | 217 | Ù | 249 | ù | |
26 | 58 | : | 90 | Z | 122 | 154 | š | 186 | 218 | Ú | 250 | ú | |
27 | 59 | ; | 91 | [ | 123 | 155 | › | 187 | 219 | Û | 251 | û | |
28 | 60 | < | 92 | \ | 124 | 156 | œ | 188 | 220 | Ü | 252 | ü | |
29 | 61 | = | 93 | ] | 125 | 157 | | 189 | 221 | Ý | 253 | ý | |
30 | 62 | > | 94 | ^ | 126 | 158 | ž | 190 | 222 | Þ | 254 | þ | |
31 | 63 | ? | 95 | _ | 127 | 159 | Ÿ | 191 | 223 | ß | 255 | ÿ | |
32 | 64 | @ | 96 | ` | 128 | 160 | 192 | 224 | à | 256 |
Here is how to create a table containing all characters returned from char using numbers 1 to 255 in Excel:
5.1 Explaining formula
Step 1 - Create numbers from 1 to 255
The SEQUENCE function creates a list of sequential numbers.
SEQUENCE(rows, [columns], [start], [step])
SEQUENCE(32, 8)
returns
{1, 2, 3, 4, 5, 6, 7, 8; 9, ... , 256}
Step 2 - Return characters
CHAR(SEQUENCE(32, 8))
returns the table above without the numbers.
6. How to identify a new line character in an Excel formula
The image above shows a formula that converts characters to ANSI code. Cell B3 contains a carriage return between 1 and 1. The number for a new line or carriage return is 10.
I used the following formula to identify the numbers for each character in cell B3.
Formula in cell C3:
You can use CHAR(10) to create a new line in a formula, see the next image below.
6.1 Explaining formula
Step 1 - Create an array
Cell B3 contains three characters. To extract each character we need an array containing numbers from 1 to 3.
The curly brackets and delimiting characters let you create an array containing constants.
{1,2,3}
Step 2 - Split text string
The MID function returns a substring from a string based on the starting position and the number of characters you want to extract.
MID(text, start_num, num_chars)
MID(B3,{1,2,3},1)
becomes
MID("1
1",{1,2,3},1)
and returns
{"1","
","1"}.
Step 3 - Calculate the number for each character
The CODE function returns a specific number for the first character of the text argument, determined by your computer's character set.
CODE(text)
CODE(MID(B3,{1,2,3},1))
becomes
CODE({"1","
","1"})
and returns {49, 10, 49}.
Step 4 - Join numbers
The TEXTJOIN function allows you to combine text strings from multiple cell ranges and also use delimiting characters.
TEXTJOIN(",",TRUE,CODE(MID(B3,{1,2,3},1)))
becomes
TEXTJOIN(",",TRUE,{49, 10, 49})
and returns 49,10,49.
7. How to create a new line in an Excel formula
The image above shows how to create a line break in a formula, cell E3 contains a formula that concatenates strings in cells B3 and C3 and inserts a line break in between.
Formula in cell E3:
7.1 Explaining formula
Step 1 - Create a new line
The following function and number 10 create a new line.
CHAR(10)
Step 2 - Concatenate text
The ampersand character concatenates strings in an Excel formula.
B3&CHAR(10)&C3
returns
John
Doe
8. How to show a new line in a cell (wrap text)
You need to allow the text to wrap in a cell, here is how to do that:
- Select the cell.
- Press CTRL + 1, and the "Format Cells" dialog box appears.
- Press with mouse on tab "Alignment, see the image above.
- Press with left mouse button on check box "Wrap text" to enable it.
- Press with left mouse button on OK button.
9. How to create a tab in an Excel formula
The picture above shows that the character is CHAR(9), however, the cell doesn't display the tab. Note that the formula bar shows the tab.
Formula in cell C3:
I am using the same formulas as in section 5 to identify the corresponding numbers for each character and concatenate tab characters with given strings.
Formula in cell E3:
10. How to create superscript characters in an Excel formula
The formula in cell B5 demonstrates how to use superscript characters, there are not that many you can use.
Formula in cell B5:
The CHAR function lets you use a couple of superscript characters see list below, and the UNICHAR function gives you more options.
174 | x® |
175 | x¯ |
176 | x° |
177 | x± |
178 | x² |
179 | x³ |
180 | x´ |
11. Function not working
The CHAR function returns
- #VALUE! error if you use a negative numerical value.
- #NAME? error if you misspell the function name.
- propagates errors, meaning that if the input contains an error (e.g., #VALUE!, #REF!), the function will return the same error.
11.1 Troubleshooting the error value
When you encounter an error value in a cell a warning symbol appears, displayed in the image above. Press with mouse on it to see a pop-up menu that lets you get more information about the error.
- The first line describes the error if you press with left mouse button on it.
- The second line opens a pane that explains the error in greater detail.
- The third line takes you to the "Evaluate Formula" tool, a dialog box appears allowing you to examine the formula in greater detail.
- This line lets you ignore the error value meaning the warning icon disappears, however, the error is still in the cell.
- The fifth line lets you edit the formula in the Formula bar.
- The sixth line opens the Excel settings so you can adjust the Error Checking Options.
Here are a few of the most common Excel errors you may encounter.
#NULL error - This error occurs most often if you by mistake use a space character in a formula where it shouldn't be. Excel interprets a space character as an intersection operator. If the ranges don't intersect an #NULL error is returned. The #NULL! error occurs when a formula attempts to calculate the intersection of two ranges that do not actually intersect. This can happen when the wrong range operator is used in the formula, or when the intersection operator (represented by a space character) is used between two ranges that do not overlap. To fix this error double check that the ranges referenced in the formula that use the intersection operator actually have cells in common.
#SPILL error - The #SPILL! error occurs only in version Excel 365 and is caused by a dynamic array being to large, meaning there are cells below and/or to the right that are not empty. This prevents the dynamic array formula expanding into new empty cells.
#DIV/0 error - This error happens if you try to divide a number by 0 (zero) or a value that equates to zero which is not possible mathematically.
#VALUE error - The #VALUE error occurs when a formula has a value that is of the wrong data type. Such as text where a number is expected or when dates are evaluated as text.
#REF error - The #REF error happens when a cell reference is invalid. This can happen if a cell is deleted that is referenced by a formula.
#NAME error - The #NAME error happens if you misspelled a function or a named range.
#NUM error - The #NUM error shows up when you try to use invalid numeric values in formulas, like square root of a negative number.
#N/A error - The #N/A error happens when a value is not available for a formula or found in a given cell range, for example in the VLOOKUP or MATCH functions.
#GETTING_DATA error - The #GETTING_DATA error shows while external sources are loading, this can indicate a delay in fetching the data or that the external source is unavailable right now.
11.2 The formula returns an unexpected value
To understand why a formula returns an unexpected value we need to examine the calculations steps in detail. Luckily, Excel has a tool that is really handy in these situations. Here is how to troubleshoot a formula:
- Select the cell containing the formula you want to examine in detail.
- Go to tab “Formulas” on the ribbon.
- Press with left mouse button on "Evaluate Formula" button. A dialog box appears.
The formula appears in a white field inside the dialog box. Underlined expressions are calculations being processed in the next step. The italicized expression is the most recent result. The buttons at the bottom of the dialog box allows you to evaluate the formula in smaller calculations which you control. - Press with left mouse button on the "Evaluate" button located at the bottom of the dialog box to process the underlined expression.
- Repeat pressing the "Evaluate" button until you have seen all calculations step by step. This allows you to examine the formula in greater detail and hopefully find the culprit.
- Press "Close" button to dismiss the dialog box.
There is also another way to debug formulas using the function key F9. F9 is especially useful if you have a feeling that a specific part of the formula is the issue, this makes it faster than the "Evaluate Formula" tool since you don't need to go through all calculations to find the issue..
- Enter Edit mode: Double-press with left mouse button on the cell or press F2 to enter Edit mode for the formula.
- Select part of the formula: Highlight the specific part of the formula you want to evaluate. You can select and evaluate any part of the formula that could work as a standalone formula.
- Press F9: This will calculate and display the result of just that selected portion.
- Evaluate step-by-step: You can select and evaluate different parts of the formula to see intermediate results.
- Check for errors: This allows you to pinpoint which part of a complex formula may be causing an error.
The image above shows cell reference B3 converted to hard-coded value using the F9 key. The CHAR function requires numerical values larger than or equal to 0 (zero) which is not the case in this example. We have found what is wrong with the formula.
Tips!
- View actual values: Selecting a cell reference and pressing F9 will show the actual values in those cells.
- Exit safely: Press Esc to exit Edit mode without changing the formula. Don't press Enter, as that would replace the formula part with the calculated value.
- Full recalculation: Pressing F9 outside of Edit mode will recalculate all formulas in the workbook.
Remember to be careful not to accidentally overwrite parts of your formula when using F9. Always exit with Esc rather than Enter to preserve the original formula. However, if you make a mistake overwriting the formula it is not the end of the world. You can “undo” the action by pressing keyboard shortcut keys CTRL + z or pressing the “Undo” button
11.3 Other errors
Floating-point arithmetic may give inaccurate results in Excel - Article
Floating-point errors are usually very small, often beyond the 15th decimal place, and in most cases don't affect calculations significantly.
Useful resources
CHAR function - Microsoft support
Formula to find if char 160 character is within cells - Reddit
Can someone explain this formula
'CHAR' function examples
Table of Contents Excel monthly calendar - VBA Calendar Drop down lists Headers Calculating dates (formula) Conditional formatting Today Dates […]
This article explains different techniques that filter rows/records that contain a given text string in any of the cell values […]
What's on this page Reverse text Insert random characters Convert letters to numbers How to shuffle characters in the alphabet […]
Functions in 'Text' category
The CHAR function function is one of 29 functions in the 'Text' category.
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Contact Oscar
You can contact me through this contact form