ASC
TheASC
function returns the numeric code of the first character of a text string. This function is commonly used to sort a list of text strings in alphabetical order based on the numeric code of their first character.
- How to use
ASC
formula? - Examples of using
ASC
formula ASC
formula not working?- Similar formulas to
ASC
Usage
Use the ASC
formula with the syntax shown below, it has 1 required parameter:
- text (required):
The text string for which to return the numeric code of the first character.
Examples
Here are a few example use cases that explain how to use theASC
formula in Google Sheets.
Sort a list of names alphabetically
You can use the ASC
function to sort a list of names alphabetically. First, create a new column next to the list of names. In the first cell of the new column, enter the formula =ASC(A1)
where A1
is the first cell containing a name. Then, drag the formula down to copy it to all cells in the column. Finally, sort both columns based on the new column, which contains the numeric codes of the first character of each name.
Filter a list of text strings
You can use the ASC
function to filter a list of text strings based on the first character of each string. For example, if you only want to include strings that start with the letter 'A', you can use the formula =IF(ASC(LEFT(A1,1))=65,A1,"")
where A1
is the first cell containing a text string. Then, drag the formula down to copy it to all cells in the column. This will only return the original string if the first character has a numeric code of 65, which is the code for 'A'.
Generate a unique ID
You can use the ASC
function to generate a unique ID based on a text string. For example, if you have a list of names and you want to generate a unique ID for each name, you can use the formula =ASC(A1)&"-"&ROW(A1)
where A1
is the first cell containing a name. This will generate an ID consisting of the numeric code of the first character of the name followed by a hyphen and the row number.
Check if a string is uppercase
You can use the ASC
function to check if a string is uppercase. For example, if you have a list of names and you want to highlight the ones that are uppercase, you can use the formula =IF(ASC(LEFT(A1,1))<=90,A1,"")
where A1
is the first cell containing a name. This will only return the original string if the first character has a numeric code less than or equal to 90, which is the code for 'Z' in ASCII.
Remove leading spaces from a string
You can use the ASC
function to remove leading spaces from a string. For example, if you have a list of names and some of them have leading spaces, you can use the formula =CHAR(IF(ASC(LEFT(A1,1))>32,ASC(LEFT(A1,1)),32))&RIGHT(A1,LEN(A1)-1)
where A1
is the first cell containing a name. This will return the original string without the leading spaces.
Common Mistakes
ASC
not working? Here are some common mistakes people make when using the ASC
Google Sheets Formula:
Forgetting to enclose text string in quotes
If you forget to enclose the text string in quotes, the formula will return a #NAME? error.
Using non-text input
If you input a non-text value, such as a number or a date, the formula will return a #VALUE! error.
Related Formulas
The following functions are similar to ASC
or are often used with it in a formula:
-
CODE
The
CODE
formula returns the numeric Unicode value of the first character in a text string. This can be useful when working with non-English characters or when attempting to identify certain characters in a text string. -
CHAR
The
CHAR
formula returns the character corresponding to the ASCII code provided. This formula is commonly used to convert a numerical value to its corresponding character in a Google Sheets cell. -
LEFT
The
LEFT
formula is used to extract a specific number of characters from the beginning of a text string. It is most commonly used to extract the first name or last name from a full name or to extract a date from a text string. -
MID
The MID formula in Google Sheets is used to extract a specific number of characters from a string, starting at a specified point. This is useful when working with large datasets and you only need a portion of the information in a cell. The formula takes in the string to extract from, the starting point, and the length of characters to extract as arguments.
-
RIGHT
The
RIGHT
formula in Google Sheets returns the rightmost characters from a string, based on the number of characters specified. It is commonly used to extract a certain number of characters from the end of a string. The formula takes two arguments: the string from which to extract the characters, and the number of characters to extract.
Learn More
You can learn more about the ASC
Google Sheets function on Google Support.