# CODE in Google Sheets: syntax and examples

URL: https://goingstellar.ro/reference/sheets/code/

CODE turns the first character of a text into its Unicode number. It is the reverse of CHAR. Use it to compare letters, sort by character or find hidden characters in imported data.

## Syntax

```
CODE(string)
```

## Arguments

- `string` (string, required: yes): The text. Only its first character is used.

## Examples

The examples use this table, starting in A1:

| Text |
|---|
| A |
| apple |
| € |
| 7 |

```
=CODE("A")
```

Result: `65`

Code of an uppercase letter. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=CODE("a")
```

Result: `97`

The lowercase letter has a different code. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=CODE(A3)
```

Result: `97`

Only the first character counts, so the rest of the word is ignored. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=CODE(A4)
```

Result: `8364`

A character outside basic ASCII returns its Unicode value. Run in a Google Sheet (English US locale) on 2026-11-29.

```
=CHAR(CODE(A2)+1)
```

Result: `B`

Shift a letter by one position: CODE gives the number, CHAR turns it back into a letter. Run in a Google Sheet (English US locale) on 2026-11-29.

## Common errors

- Only the first character is read. CODE("apple") returns 97, the code of "a".
- An empty string returns #VALUE!. Wrap it in IFERROR if the source can be blank.
- Case matters: "A" is 65 and "a" is 97.
- A number is read as text. CODE(5) returns 53, the code of the digit "5", not 5.

## Compared with Excel

Same syntax in Excel.

## Related functions

- [CHAR](https://goingstellar.ro/reference/sheets/char/)
- [LEN](https://goingstellar.ro/reference/sheets/len/)
- [SUBSTITUTE](https://goingstellar.ro/reference/sheets/substitute/)

## Sources

- [CODE (Docs Editors Help)](https://support.google.com/docs/answer/3094122)

