Skip to content
Excel

CODE function in Excel

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

=CODE(text)

CODE syntax and parameters

One argument, one required.

  • textstringRequired

    The text for which you want the code of the first character.

CODE examples

Formulas you'll actually reuse.

  1. The code of the first character — 32 means a hidden leading space:

    =CODE(A2)

    Result32

  2. Check the last character — 160 is a non-breaking space that TRIM won't remove:

    =CODE(RIGHT(A2, 1))

    Result160

CODE in Google Sheets

Same name — your formula ports as-is.

Try CODE in the playground

Edit the example — nothing to install.

Preloaded with the CODE formula from Example 1 — change anything and watch it respond.

Loading the editor…