Contact

CODE Function in Google Sheets: Examples, Pitfalls & Compatibility

Text Beginner Google Sheets

CODE in Google Sheets: inspect the numeric code of the first character in a text value. Includes worked examples and application-specific cautions.

Verification status: Official documentation referenced; example outcomes independently reasoned or arithmetically checked where stated. Not executed in Google Sheets. How formula examples are checked

Quick answer: Use CODE in Google Sheets to inspect the numeric code of the first character in a text value. The official CODE reference is the source for the function definition and platform-specific rules described below.

Syntax and arguments

=CODE(string)

string (required): A nonempty text value or a cell containing it. Only the first character is inspected.

Examples use English function names, comma argument separators and decimal points. Adapt formula separators to your workbook settings, not punctuation inside quoted text.

When to use it

Use CODE to investigate the beginning of a suspicious identifier, not to encode a complete word. It can help distinguish case or an unexpected leading character. To inspect a later position, isolate that character with MID before passing it to CODE.

Three worked examples

Each example is independent. Where input cells are listed, enter those values first; otherwise the formula is self-contained. Expected outputs are independently checked calculations or documented error expectations, not captured results from Google Sheets.

Example 1: Inspect a leading check mark

=CODE("✓ Done")

Expected result: 10003.

The first character is the Unicode check mark. Neither the space nor Done is encoded by this call.

Example 2: Inspect a leading currency symbol

=CODE("£12")

Expected result: 163.

The pound sign is the first character. This is a text inspection example, not a numeric conversion of the amount.

Example 3: Check a Unicode round trip

=CODE(CHAR(9733))

Expected result: 9733.

CHAR constructs the star and CODE inspects it. The expected number is its Unicode code point, regardless of the glyph’s appearance.

Put it to work safely

Begin with a short known string and compare its first-character code with the problematic value. A leading space will be inspected before any letter that follows it. Retain both the original string and the numeric diagnostic while investigating an import issue. Do not automatically delete a character merely because its code differs from a familiar ASCII value.

Common mistakes and fixes

Only one code is returned for a whole word. That is the function’s scope. It inspects the first character rather than generating a sequence for the whole string.

The code describes a space instead of a letter. Inspect the original text for a leading space. Decide whether trimming is appropriate before changing it.

A number differs across applications. The character-code system matters, especially outside ASCII. Verify the application-specific definition before using codes as durable identifiers.

Google Sheets-specific notes

Google Sheets CODE returns the Unicode number of the first character. A string containing several characters still produces one code. This makes the function suitable for checking a leading Unicode symbol without assuming an 8-bit character set. See the vendor reference for the current definition.

Excel and Google Sheets comparison

ASCII letters are useful baseline tests across Excel and Sheets. Codes for Unicode symbols or extended characters are not evidence of complete cross-platform equivalence. A matching first-character code also says nothing about the rest of the string.

Compare the CODE guide for Microsoft Excel and its official documentation. Having a guide in both libraries establishes two documented references, not a certificate of identical behavior across releases, locales or file conversions.

Evidence and testing scope

Editorial verification: Official references retrieved on 2026-10-12. The three worked cases are included in this release’s reproducible Python checking suite. It checks the stated arithmetic, calendar or text model and the expected documented error classification; it is not the Google Sheets calculation engine. No native application run, UI screenshot, maximum-size benchmark or cross-version certification is claimed. Review the editorial testing standards before relying on a formula in a critical workbook.