Category: FUNCTION | Updated: 2026-11-22

How to Use the CODE Function in Google Sheets | Get the Unicode Number of a Character

How to Use the CODE Function

The CODE function is a Google Sheets text function that returns the decimal Unicode numeric code for the first character in a specified text string.

Syntax

=CODE(string)
  • string: The text string or cell reference whose first character’s Unicode value you want to look up (required).

Examples

Here is an example of retrieving Unicode values for various characters.

Row Column A (Target Text) Column B (Formula) Column C (Result)
1 Target Text Formula Result
2 A =CODE(A2) 65
3 a =CODE(A3) 97
4 あ =CODE(A4) 12354
5 Apple =CODE(A5) 65
  • Explanation: Even when a multi-character string like Apple (row 5) is given, CODE returns 65, the code for the leading A. Uppercase and lowercase letters have different codes.

Common Errors and Tips

  • Blank cells or empty strings return #VALUE!: Passing an empty cell or "" causes #VALUE! because there is no character to evaluate.
  • Full-width and half-width characters have different codes: For example, half-width A is 65, whereas full-width A is 65313, which is useful for detecting character types during data cleansing.
  • Combining with CHAR: You can add 1 to a CODE result and pass it to CHAR (e.g., =CHAR(CODE("A")+1) → B) to generate sequential letters.

Frequently Asked Questions

Q. What happens if I pass a string with two or more characters to CODE?

A. Only the first character of the string is evaluated and its Unicode value is returned. All subsequent characters are ignored.

Q. Which function converts a numeric code back into a character?

A. Use the CHAR function. For example, "=CHAR(65)" returns "A", the reverse of CODE("A").