returns the numeric code for the first character in a text string.
CODE(text)
returns the numeric code for the first character of the text string text, in the range 0-255.
Codes greater than 127 may depend on system's character mapping (for example iso-8859-1, iso-8859-2, Windows-1252, Windows-1250), and hence may not be portable.
CODE("H")
returns 72, the character code for "H".
CODE("Hello")
also returns 72.
Imagine you are managing inventory for a small electronics company. Your company uses a simple system where each product's SKU (Stock Keeping Unit) starts with a letter that represents the product category.
You want to create a quick validation rule to ensure that the SKUs entered into your inventory sheet are valid and fall within one of these categories. You can use the CODE function to check the first character of the SKU.
Table: Inventory Data
SKU | Product Description | CODE(SKU) | Validation Check | ||
|---|---|---|---|---|---|
A | B | C | D | ||
1 | C101-A | Desktop PC | 67 | Valid | |
2 | L205-B | Ultrabook | 76 | Valid | |
3 | P301-Z | Laser Printer | 80 | Valid | |
4 | C102-A | All-in-One PC | 67 | Valid | |
5 | X404-F | External HDD | 88 | Invalid | |
6 | M502-G | 27-inch Monitor | 77 | Valid |
Explanation:
How you would use this in the real world:
You could add another column for "Validation" and use a formula that checks if the CODE value is one of the valid codes (67, 76, 77, 80, 84).
In this example, the formula in the "Validation Check" column would use the result of the CODE function. The formula IF(OR(C5=67,C5=76,C5=77,C5=80,C5=84),"Valid","Invalid") checks if the numeric code is one of the approved codes. Since the SKU X404-F starts with 'X' (code 88), the validation check correctly flags it as "Invalid," alerting the user to a potential data entry error.
PRODUCT & FEATURES
RESOURCES
Terms | Privacy | Spam Policy
© 2026 Zapof