Contact

CODE Function in Microsoft Excel: Examples, Pitfalls & Compatibility

Text Beginner Microsoft Excel

CODE in Microsoft Excel: 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 Microsoft Excel. How formula examples are checked

Quick answer: Use CODE in Microsoft Excel 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(text)

text (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 Microsoft Excel.

Example 1: Inspect the start of an identifier

=CODE("C7")

Expected result: 67.

Only the capital C is inspected. The following digit does not contribute to the result.

Example 2: Distinguish lowercase from uppercase

=CODE("c7")

Expected result: 99.

The lowercase c has a different ASCII code from the capital C in the preceding example.

Example 3: Inspect a character at a known position

=CODE(MID("AB9",2,1))

Expected result: 66.

MID extracts one character at position 2 before CODE runs, so the inspected character is B.

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.

Microsoft Excel-specific notes

Excel CODE reports the first character using the computer character set, which Microsoft distinguishes for Windows and Macintosh. For a Unicode-specific inspection, do not assume CODE is interchangeable with a Unicode function. 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 Google Sheets 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 Microsoft Excel 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.