Skip to main content

CODE function

Description

The CODE function returns a numeric code for the first character in a text string.

The returned code corresponds to the character set used by your computer.

Operating environment Character set
Macintosh Macintosh character set
Windows ANSI

If you want to return the character specified by the code number, please use CHAR Function.

Syntax

CODE(text)

Parameters

Text Required. The text for which you want the code of the first character.

Examples

Example 1

The example may be easier to understand if you copy the example data (include header) in the following table, and paste it in cell A1 of a new Excel worksheet. If you need to, you can adjust the column widths to see all the data.

Formula Result Description
=CODE("Excel") 69 Displays the numeric code for Excel (the first character, 69)
=CODE("E") 69 Displays the numeric code for E (69).
=CODE("e") 101 Displays the numeric code for e (101)
=CODE("€") 128 Displays the numeric code for € (128)

If you remember the code of a symbol, you can fast input it with follow tip, For example:

you know the code of is 128 (CODE("€")=128), hold down the ALT key, type 1 2 8 on the number pad, then releasing ALT, it will enter symbol.

Example 2: Data validation - check for alphabetic characters only

If cell A1 contains a text string, the below formula will check it is all alphabetic characters:

=AND(N(CODE(RIGHT(UPPER(A1),ROW(INDIRECT("1:"&LEN(A1)))))>{64,90})={1,0})

Note that this is a array formula, please end this formula with CTRL SHIFT ENTER.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>