Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Returning an ANSI Value.
by Allen Wyatt
(last updated November 24, 2018)
You may have a need to determine the ANSI value of the text in a particular cell. You can do this using the CODE worksheet function. This function returns a numeric value that represents the ANSI value of the first letter in the referenced cell. For instance, if cell A1 contains the text "My Stuff," and that B1 contains the following:
In this instance, B1 will have a result of 77, which is the ANSI value of M, the first character in A1.
If the value in the referenced cell is numeric (such as 34 or 2798), then the CODE function treats the numeric value as if it were text and returns the ANSI value of the first digit in the value. Thus, if A1 contained 34, then CODE would return 51, which is the ANSI value of "3."
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (7012) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Office 365. You can find a version of this tip for the older menu interface of Excel here: Returning an ANSI Value.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
Character codes are the numeric values used, by a computer, to signify various alphanumeric characters. You can use the ...Discover More
When you filter data, Excel displays only a portion of what is really in a worksheet. If you want to count the number of ...Discover More
The data validation capabilities of Excel are really handy when you want to limit what is put into a cell. However, you ...Discover More
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.