Google Sheets ASC Function: How to Convert Text to ASCII
In this article
The ASC function in Google Sheets converts the first character of a text string into its corresponding numeric ASCII (American Standard Code for Information Interchange) value. To use it, simply enter =ASC(text) into a cell, where "text" is either a cell reference or a string enclosed in quotation marks. This function is primarily used for data validation, identifying hidden characters, and performing low-level text analysis where the specific numeric code of a character is required for logic or sorting.
What You'll Need
- A Google account with access to Google Sheets.
- A dataset containing text strings, symbols, or numbers that you wish to convert to their numeric character codes.
- A basic understanding of cell referencing (e.g., knowing how to point a formula to cell A1).
Step-by-Step
- Open your Google Sheet: Launch your browser, navigate to Google Sheets, and open the specific spreadsheet where your data is located.
- Identify the Target Cell: Locate the cell containing the text you want to analyze. For example, if cell A2 contains the letter "A", this is your target.
- Select the Output Cell: Click on an empty cell where you want the resulting ASCII number to appear. It is common practice to place this in the column immediately to the right of your data.
- Enter the Formula: Type
=ASC(into the output cell. - Define the Input: You have two options here:
- Cell Reference: Click on the target cell (e.g., A2) or type the reference manually. Your formula will look like
=ASC(A2). - Direct Text: Type the character inside double quotation marks. For example,
=ASC("B").
- Cell Reference: Click on the target cell (e.g., A2) or type the reference manually. Your formula will look like
- Complete and Execute: Close the parenthesis
)and press Enter. The cell will now display the decimal representation of the first character in that string. For instance, if the input was "A", the result will be 65. - Apply to Multiple Rows: To convert an entire column of data, click the small blue square (fill handle) at the bottom-right corner of the output cell and drag it down to the end of your data range. Google Sheets will automatically adjust the cell references for each row.
Common Mistakes
One of the most frequent errors is assuming the ASC function converts the entire word into a sequence of numbers. The ASC function only evaluates the very first character of the provided string. If you input "Apple", the function only returns the code for "A" (65) and completely ignores "pple". To convert an entire word, you must combine ASC with other functions like MID or SEQUENCE to iterate through each character position.
Another common mistake is forgetting the double quotation marks when entering text directly into the formula. Writing =ASC(A) instead of =ASC("A") will cause Google Sheets to look for a named range called "A". Since that range likely does not exist, the sheet will return a #NAME? error.
Users also frequently confuse the ASC function with the CHAR function. While ASC converts a character to a number, CHAR does the exact opposite: it converts a number back into a character. Using =ASC(65) will not give you "A"; instead, it will treat the number 65 as text and return the ASCII value of the character "6", which is 54.
Tips
To analyze a full string of text, use the ASC function in conjunction with the MID function. By creating a helper column that identifies the position of each character, you can extract the ASCII value for every letter in a word. For example, if your text is in A2, using =ASC(MID($A2, COLUMN(A1), 1)) and dragging it across columns will provide the numeric code for each subsequent character in the string.
The ASC function is incredibly useful for finding "invisible" characters. Sometimes data imported from external software or websites contains non-breaking spaces or hidden control characters that prevent VLOOKUP or MATCH functions from working. By using ASC on a cell that looks empty but is behaving as if it contains data, you can identify the exact numeric code of that hidden character and then use the SUBSTITUTE function to remove it.
If you are working with international characters or emojis, be aware that ASC is designed for the standard ASCII set (0-127). While Google Sheets handles Unicode, the ASC function specifically targets the basic character set. For more complex character encoding needs, you may need to explore Apps Script or specialized add-ons that handle UTF-8 encoding more comprehensively.
Troubleshooting
If your formula returns a #VALUE! error, it usually means the input is not a valid text string or the cell is completely empty. Ensure that the cell you are referencing actually contains at least one character. If the cell is blank, the function has nothing to evaluate and will trigger this error.
If you see a #NAME? error, check your syntax. This almost always happens because you omitted the quotation marks around a text string or misspelled the function name. Ensure the formula begins with an equals sign and that the function is spelled exactly as ASC.
If the number returned is not what you expected, check for leading spaces. If a cell contains " A" (a space followed by the letter A), the ASC function will return 32 (the code for a space) rather than 65. To fix this, wrap your reference in the TRIM function: =ASC(TRIM(A2)). This removes leading and trailing whitespace before the ASC function processes the first character.
If the formula is not updating when you change the source text, check your calculation settings. While Google Sheets usually calculates in real-time, ensure your internet connection is stable and that the sheet is not currently stuck in a "Calculating..." state in the bottom right corner.
Frequently Asked Questions
Can ASC convert a whole sentence into numbers?
No, the ASC function only returns the numeric value of the first character of the string. To convert a whole sentence, you must use a combination of MID and ASC across multiple cells or use a custom Google Apps Script function.
What is the difference between ASC and CHAR?
ASC is for encoding (Character → Number), while CHAR is for decoding (Number → Character). For example, =ASC("A") returns 65, and =CHAR(65) returns "A".
Does ASC work with numbers in cells?
Yes, but it treats the number as a text character. If a cell contains the number 1, =ASC(A1) will return 49, which is the ASCII value for the character "1", not the numeric value of the number itself.
Why does =ASC(" ") return 32?
In the ASCII standard, the space character is assigned the decimal value of 32. This is why the function returns 32 whenever the first character encountered is a standard space.
Can I use ASC to find hidden characters in my data?
Yes, this is one of its most practical uses. By applying ASC to a cell that appears empty or has strange spacing, you can determine if there are non-printing characters (like tabs or carriage returns) that are interfering with your formulas.
Does the ASC function support emojis?
The ASC function is designed for the basic ASCII character set. While it may return a value for some extended characters, it is not the appropriate tool for analyzing complex Unicode characters or emojis, which require much larger numeric values than the standard ASCII range provides.