Description
Use this function to return the numeric code for the first character in a text string. Supported in Chains.
CODE returns the numeric Unicode character code corresponding to the first character of the provided text string.
Syntax
CODE(text)
Inputs
This function accepts the following argument:
| Name | Required | Description | Valid input |
|---|---|---|---|
text |
Yes | The text string for which you want to find the code of the first character. | A text string, a reference to a cell containing text, or a formula which results in text. |
Example
Sample data
| A | B |
|---|---|
| Character | Description |
| A | Uppercase A |
| a | Lowercase a |
| 1 | Number one |
| ! | Exclamation mark |
| Hello | Word |
Sample Formulas
| Formula | Description | Result |
|---|---|---|
=CODE(A2) |
Returns the code for uppercase A | 65 |
=CODE(A3) |
Returns the code for lowercase a | 97 |
=CODE(A4) |
Returns the code for the number 1 | 49 |
=CODE(A5) |
Returns the code for the exclamation mark | 33 |
=CODE(A6) |
Returns the code for the first character of "Hello" | 72 |
Notes
- CODE returns the number representing the character in the Unicode character set.
- If the text argument is empty, CODE returns a #VALUE! error.
- CODE only considers the first character of the text string, even if the string contains multiple characters.
- CODE is often used in combination with CHAR, which performs the reverse operation (converting a number to its corresponding character).
Tips
- You can use CODE to compare characters based on their Unicode values, which can be useful for sorting or filtering Sample Data.
- Combine CODE with other text functions such as LEFT, MID, or RIGHT to work with specific characters in a string.
- Remember that CODE returns different values for uppercase and lowercase letters, as well as for numbers and special characters.
- To convert between uppercase and lowercase letters, you can use CODE in combination with simple math operations (Example:
CODE("A") + 32gives the code for "a"). - When working with non-ASCII characters, be aware that CODE returns Unicode values, which may be different from ASCII codes for extended characters.
Related functions
CHAR
CODE
CONCATENATE
CONCATENATEIF
FIND
LEFT
LEN
LOWER
MID
PROPER
REPT
RIGHT
SEARCH
SUBSTITUTE
TEXT
TEXTJOIN
TRIM
UNICHAR
UNICODE
UPPER