HomeGoogle DocsSpreadsheetHow to Use the CODE Function in Google Sheets

How to Use the CODE Function in Google Sheets

Published on

The CODE function in Google Sheets returns the Unicode code point value of a character. This function provides a numeric output. If you are looking for a function to return characters like “©,” “µ,” “¾,” etc., consider using the CHAR function.

If you use a text string instead of a single character in the CODE function, it will return the value of the first character, and other characters in the string will not be considered.

In Google Docs Spreadsheet, I typically use the CODE function to determine the value of the output from the CHAR function.

I recently employed these functions in a tutorial to create complex passwords based on provided names and dates of birth.

Therefore, you should understand what the CODE function is and how it differs from the CHAR function in Google Sheets.

As a side note, you can use the UNICODE function instead of the CODE function in Google Sheets. Why are there two functions?

The presence of both functions is due to compatibility with Excel, which includes both CODE and UNICODE functions. The CODE function was introduced in earlier versions of Excel, which initially supported the ANSI/Macintosh character set. In Google Sheets, the CODE function has been expanded to encompass Unicode characters, providing broader character support.

Syntax and Argument

Here is the syntax of the CODE Function in Google Sheets:

CODE(string)

string: Required. The string for which you want the code of the first character.

Decoding Character Conversions: Comparing the CODE and CHAR Functions in Google Sheets

Let’s explore the relationship between the CODE and CHAR functions with a few examples below.

Example #1:

The following CODE formula returns the Unicode value of the Omega character:

=CODE("Ω")  // returns 937

Whereas the following CHAR formula returns the Omega character:

=CHAR(937)  // returns "Ω"

Example #2:

The following formula returns the numerical Unicode code point of the first character, which is “A,” in the word “APPLE”:

=CODE("APPLE")  // returns 65

Therefore, the following CODE formula would also return the value 65 for the character “A”:

=CODE("A")  // returns 65

Now, let’s consider the CHAR formula:

The formula =CHAR(65) would return the character “A”.

I hope this helps you understand how to use the CODE function in Google Sheets.

Note: The Unicode values of the capital letters (English alphabets) A to Z range from 65 to 90, and the small letters range from 97 to 122.

Practical Use of the CODE Function in Google Sheets:

You can employ the CODE function to convert a case-insensitive formula into a case-sensitive one in a clever way. To see this in action, take a look at my case-sensitive VLOOKUP formula where I’ve utilized the CODE function.

Unicode Characters and Map Values in Google Sheets

You can refer to this wiki page to find Unicode characters and their code values. Here are some of the most useful ones (screenshot).

CODE Function Examples in Google Sheets

In this example, I’ve used the formula =CHAR(A2) in cell B2 and dragged it down. In cell C2, there is a CODE formula =CODE(B2) that is also dragged down to fill the cells.

I personally don’t find much use for this function, but it may have different applications for you. For me, the CHAR function is quite useful in Google Sheets.

Feel free to explore some of my tutorials that demonstrate how to maximize the benefits of the CHAR function in Google Sheets.

Related:

  1. How to Get Subscript and Superscript Numbers in Google Spreadsheets.
  2. 5-Star Rating in Google Sheets Including Half Stars.
  3. How to Create a Percentage Progress Bar in Google Sheets.
  4. Insert Special Characters Without Add-on in Google Sheets.
  5. Inserting Bullet Points in Google Sheets.
Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

SORT and SORTBY – Excel Vs Google Sheets

While Excel offers the SORT and SORTBY functions for sorting a table, Google Sheets...

Get Top N Values Using Excel’s FILTER Function

When using the FILTER function in Excel to extract the top N values, it's...

XLOOKUP in Excel: Working with Visible Rows in a Table

In Excel, the XLOOKUP function isn't inherently designed to exclusively work with visible rows;...

More like this

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

Google Sheets Bar and Column Chart with Target Coloring

To color each data point in the column or bar chart according to the...

Analyzing Column A Between Non-Adjacent Values in Column B: Google Sheets

This tutorial addresses a common scenario encountered in Google Sheets: how to sum, average,...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.