FormulaCraft

CODE

CODE is the inverse of CHAR — it takes a text string and returns the numeric character code of its first character according to the ASCII/ANSI table. Use it to inspect character values, detect non-printing characters, or build custom sort logic based on character codes.

Excel
=CODE(A2)
Google Sheets
=CODE(A2)

Verified example

Computed by a real spreadsheet engine on the sample data below.

TextCode
Apple=CODE(A2)
Banana=CODE(A3)
Cherry=CODE(A4)
Date=CODE(A5)

=CODE(A2)65

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

How it works

  1. 1Place the text whose first character you want to inspect in a cell (e.g., 'Apple' in A2).
  2. 2Enter =CODE(A2) to return 65, the code for 'A'.
  3. 3Use CODE inside an IF or CHOOSE to branch logic based on whether a cell starts with a letter, digit, or special character.

Need a version for your data?

Try: “Find the ASCII code of the first character in each cell to detect leading symbols

Related

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: