Contact

CODE Function in Apple Numbers: Syntax, Examples, and Troubleshooting

Text Beginner Apple Numbers

Find the decimal Unicode code of the first character of a text string in Apple Numbers.

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

Quick answer: =CODE("A") returns 65. CODE takes a text string and returns the decimal Unicode number of its first character. =CODE("abc") returns 97, not separate codes for a, b, and c. Apple documents both behaviours in CODE — Functions Help 15.4.

Purpose and how it differs from CHAR

Use CODE to inspect a leading character in imported text, investigate unexpected leading spaces, or convert a Unicode text symbol into its numeric identifier. A returned code is numeric and can be compared with other numbers; it is not the displayed character itself. Apple’s CHAR function works in the opposite direction for a permitted decimal code, but CHAR has an explicit 32–65535 validity restriction; a successful CODE computation does not guarantee that passing every possible result into CHAR will succeed.

CODE examines only the first character, so CODE("Cat") is about C, not the full word. Do not mistake CODE for a hashing function or a way to encode an entire text string uniquely.

Exact official syntax and arguments

=CODE(code-string)

Item: code-string

Required?
Yes

Type
String/text

Rule
Only the first character is used; later characters are ignored.

Item: Extra arguments

Required?
No documented support

Type
—

Rule
One text input only.

Item: Default

Required?
None documented

Type
—

Rule
Pass a nonempty meaningful string for the examples below.

Apple says CODE returns a decimal Unicode value. Its individual help page does not specify what error text appears for an empty string, how it treats supplementary Unicode planes such as emoji, or whether all composed/decomposed characters map identically; do not assert an untested answer for those cases.

Reproducible worksheet: first-character inspector

Create a Numbers table named Code Inspector, with the following text inputs in column A. Enter =CODE(A2) in B2, then fill down to B6.

Row: 2

A: text input
A

B formula
=CODE(A2)

Expected number
65

Evidence basis
Apple example and independent Unicode map

Row: 3

A: text input
abc

B formula
=CODE(A3)

Expected number
97

Evidence basis
Apple example: first a only

Row: 4

A: text input
三二一

B formula
=CODE(A4)

Expected number
19977

Evidence basis
Apple’s explicitly documented example

Row: 5

A: text input
Zebra

B formula
=CODE(A5)

Expected number
90

Evidence basis
Independent code-point mapping of Z

Row: 6

A: text input
space (one leading ordinary space)

B formula
=CODE(A6)

Expected number
32

Evidence basis
Leading U+0020 space; independently mapped

For a no-table demonstration use =CODE("f") → 102, directly reproduced from Apple’s documentation. Apple does not require a separate function for Latin alphabet or Chinese example characters in its stated first-character mapping. All shown results are expected/documented, not observed application runs.

Advanced: flag ASCII uppercase initial letters

With A2 as a nonempty text value, enter:

=IF(AND(CODE(A2)>=65,CODE(A2)<=90),"Starts A-Z","Other")

Expected: Apple → Starts A-Z; Zebra → Starts A-Z; apple → Other; 三二一 → Other. This is an ASCII uppercase initial classifier, not a general Unicode test for all capital letters in every writing system. The comparisons derive from Unicode codes 65–90. The formula has not been executed in Numbers.

For a simple import-data diagnostic, =IF(CODE(A2)=32,"Leading ordinary space","No leading U+0020") detects only a leading U+0020 ordinary space, assuming A2 is nonempty. It does not identify tabs, nonbreaking spaces, or visually similar Unicode spaces as ordinary spaces.

CODE with CHAR — safe round trip example

For A, both =CODE("A") and =CHAR(65) are supported by Apple’s documented descriptions. =CHAR(CODE("A")) is expected to return A, as each step uses a permitted input. The same assumption is not justified for every arbitrary Unicode character: CHAR explicitly excludes some codes and cannot accept code points greater than 65,535. The round-trip result was independently reasoned, not natively observed.

Troubleshooting

Symptom Why it happens What to do
=CODE("abc") returns 97, not three values Apple uses only the first character. Inspect each character separately when you need more than the initial one.
CODE returns 32 when the cell looks like it starts with a letter A single ordinary leading space is itself the first character. Inspect the stored text; do not assume all whitespace is U+0020.
Unexpected results for accented glyphs A visually similar character may be stored as one precomposed code point or multiple code points. Verify normalization in source data; exact CODE handling for combining sequences requires native testing.
Empty text input Apple’s checked function page gives no specific empty-string error example. Add input validation; do not publish a guessed error label.
Emoji or unsupported code points The Apple page does not establish supplementary-plane handling. Mark as unverified for your platform.
Excel returns platform-dependent values for some characters Microsoft documents ANSI/Mac character-set behaviour for Excel CODE. Do not assume full Unicode equivalence.

Locale, same-table formulas and cross-platform differences

CODE has one argument. Numeric results such as 65 and 19977 are not affected by thousands separators in the underlying value; their display formatting may differ. If you embed CODE in IF or another multi-argument function and your document uses a comma as decimal separator, Apple’s Functions overview specifies semicolons as argument separators. Use A2-style references within the same table; other tables and sheets may require a fully qualified table reference (Apple cell-reference help).

Comparison with other spreadsheet programs: Microsoft’s Excel CODE describes a code corresponding to the platform’s character set (Windows ANSI versus Macintosh); it is not a promise to match Apple Numbers’ Unicode code values for every non-ASCII character. Google Sheets CODE explicitly maps the first text character to a Unicode number, making many examples conceptually similar, but this is documentation comparison, not an executed cross-app regression test.

Apple CHAR converts eligible codes back into characters. Apple CLEAN is useful when imported text contains certain invisible characters; it does not reveal all character codes.

Sources checked 2026-10-12: Apple CODE; Apple CHAR; Apple Functions overview; Apple cell references; Microsoft Excel CODE; Google Sheets CODE.

  • CHAR — continue with a related Apple Numbers calculation.
  • CLEAN — continue with a related Apple Numbers calculation.
  • T — continue with a related Apple Numbers calculation.
  • REPT — continue with a related Apple Numbers calculation.
  • FIXED — continue with a related Apple Numbers calculation.

For a software-specific comparison: Microsoft Excel CODE, Google Sheets CODE, LibreOffice Calc CODE. A shared name does not establish identical argument, error or version behaviour.

How this guide was checked

The linked official function documentation was reviewed on October 12, 2026. Apple’s Formulas and Functions Help 15.4 identifies the documentation edition, not a minimum Numbers release or a guarantee of historical platform parity. Selected worked examples were checked using independent mathematical or text-processing models; results are expected values, not observations from the spreadsheet application. Native Apple Numbers execution was not performed. Undocumented coercion, exact error messages and platform-specific behaviour remain unverified.

View reproducible example inputs and independent check results. This record is not a native spreadsheet test log.