Quick Navigation
CODE Function
Summary
The Excel CODE function converts the first character of a text string into its corresponding numeric ASCII code. This is essential for text analysis, character manipulation, and understanding how Excel interprets different characters based on your operating system's character set.
Syntax
CODE(text)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| text | Text |
Yes | Required text argument containing the first character to analyze |
Using the CODE Function
CODE is perfect for scenarios requiring character code analysis, such as validating input characters, creating custom sorting algorithms, or debugging text import issues. It reveals exactly how Excel interprets characters from your specific operating system.
Common CODE Examples
Basic Character Code Lookup
=CODE("A")
Returns 65, the ASCII code for uppercase letter A
Special Character Analysis
=CODE("!")
Returns 33, the ASCII code for the exclamation mark
Dynamic Text Input
=CODE(A1)
Converts first character of cell A1 to its numeric code value
Frequently Asked Questions
Common Errors and Solutions
#VALUE! error
Cause: Non-text argument provided
Solution: Ensure text parameter contains valid text string
Notes
- Windows uses ANSI character set
- Macintosh uses Macintosh character set
- Always returns code for FIRST character only
- Maximum value is 255 for standard ASCII extended set
Compatibility
Available in: Excel 2007, Excel 2010, Excel 2013, Excel 2016, Excel 2019, Excel 2021, Excel 365
Not available in:
Content last reviewed: December 9, 2025
Update frequency: As needed
Excel versions tested: Excel 2007+