Features of !SEMTools

CODE

CODE function examples in Excel
CODE – function usage examples
Function categoryText
VolatilityNon-volatile
Similar functionsCHAR, UNICODE, UNICHAR

What does the CODE function do?

This function returns the ANSI value of the first character in the input string. Simply put – it converts a letter to a number (which corresponds to it in the current system encoding).

The ANSI character set is used by Windows to identify each keyboard character with a unique number.

The ANSI set contains 255 characters. The set depends on the current system language, so the same formulas may return different values on different computers.

Formatting

Similar to all text functions, the CODE function converts the input value to text. During this conversion, characters in numeric format cells may change. This particularly applies to dates, times, and percentage format.

Syntax

=CODE(Cell_or_value)

The function is case-sensitive – letters in different cases have different codes.

For characters not present in the current system character table, 63 is returned, which when reverse converted by the CHAR function will return a question mark.

If an empty cell or zero-length string is passed to the function, it returns a #VALUE! error.

Windows character codes for Russian language

The table below shows all characters and their codes when the system language is Russian.

Characters and their codes for Windows-1251 encoding
Complete table of character and code mapping in Windows-1251 encoding (Cyrillic)

Usage examples

One of the bright examples I considered in a separate article – How to create alphabet in Excel. The article explains how to add one to a letter to get the next one. Of course, we don’t add to the letter itself, but to its code. In general, see the article.

Like the article? Help its author! Buy !SEMTools, it has lots of useful instruments to process text data.

This post is also available in RU.