Formualizer Docs

CODE

Returns a numeric code for the first character in a text string.

Returns the numeric code of the first character in text.

CODE mirrors Excel behavior with Windows-1252 compatibility mappings.

The Formualizer engine in this repository at 0.15.0 plus unreleased changes computes the example results. Known differences from Excel are listed on this page.

Syntax

=CODE(text)

Arguments

ArgumentTypeRequiredDefault
textanyRequired—

Remarks

  • Only the first character is inspected.
  • Text-like coercion is applied to non-text scalar inputs.
  • Known Unicode characters in the Windows-1252 extension map back to their Excel codes.

Error cases

  • Empty text returns #VALUE!.

Examples

Return the numeric character code for the first character in a string.

Formula =CODE("ABC")

Expected result 65

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Change the leading character while keeping the rest of the string.

Formula =CODE("aBC")

Expected result 97

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Read the numeric code of a single space.

Formula =CODE(" ")

Expected result 32

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

An empty string has no first character to encode.

Formula =CODE("")

Expected result #VALUE!

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

ASCII code

Formula =CODE("A")

Expected result 65

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

Extended mapping

Formula =CODE(CHAR(128))

Expected result 128

Try this formula

This editor runs the published Formualizer 0.14.0 package, so the last digits can differ and functions newer than that release return #NAME?.

FAQ

What if the input text is empty?

CODE returns #VALUE! because there is no first character to evaluate.

Implementation

Engine source

On this page