3 Ways to Get the Hexadecimal Color Code from a Cell in Google Sheets

This post is going to show you how you can get the hexadecimal code from a colored cell in Google Sheets.

Spreadsheets usually focus on numbers and text, but colors can also be an important part.

Color helps to bring style and add context to the spreadsheet. With most spreadsheets being a cluster of numbers and words, colors can make it easier on the eye.

It will be easier to stick with a particular color if you know the hex code and can use it every time you need the same color.

This post is going to show you how to extract the hexadecimal code from any colored cell in your spreadsheet so you can reuse it anywhere else.

Get your copy of the example workbook with the above link to follow along.

What is a Hexidecimal Color Code?

The hexadecimal code is a 6 character code that is used to identify colors. It defines each color by specifying the amount of red, blue, and green.

These hex codes are used extensively on the web and are one of the main ways to set a color digitally. They make it very easy to reference any color of choice.

When you choose a color from the available color options or create a custom color in Google Sheets, you can note the hexadecimal code so you can apply the same color to other places.

How to Fill the Cell Color

The most used function of colors in spreadsheets is that they can highlight and draw attention to important details.

You can add colors to a cell or a range of cells using the Fill color icon in the toolbar section of your spreadsheet.

When you use the Fill color tool, you will find that it has various shades of colors from which you can choose to add to your selected cells. Each color has a specific hex code associated with it.

Get the Hex Code from Copy and Paste

This post will discuss several methods you can use to get the hexadecimal code of any color in your spreadsheet.

Suppose you are looking for a suitable color to use on the column headers of this small sample.

First, select the year column header and add color using the Fill color found in the toolbar menu.

This is the standard way to add the color format to your cells.

To get the hex code of this color, select the cell and go back to the Fill color command. Select the addition symbol under CUSTOM.

When you click on the addition icon you get the custom color picker where you can find the Hex code of the color currently in use. In this example the hex code is #38761d.

Highlight and copy the Hex code and click on OK to exit the menu.

To apply the same color to the other column headers, click on the addition icon under CUSTOM.

You will find that the Hex code is different. That is because the color of the cell is white, so the #ffffff Hex code represents the color code for white.

Delete the code in the box and paste the code you copied earlier. Click on OK to save the new color selection.

You can easily use the same shade of color in your spreadsheet when you note down the hexadecimal code.

Use a Chrome Extension

You will need to download a chrome extension for this method. The name of the extension is Easy Color Picker. You can download it from this link.

The link would take you to the chrome web store page where you can add the extension to your browser.

With this tool, you can use colors from other web pages in your spreadsheet, which is a great option because it extends your pool of choices.

You can pin the tool to the extension tab of your browser for easy access.

This is how to use the tool once you download it.

1. Open the webpage containing the color you want to use in a separate tab.

2. Use the Pick tool from the Easy Color Picker to select the color you want to use on the webpage.

3. When you select the Pick tool, a small square box appears. The square box previews or reflects the background color of the arrow’s location. As you move around the webpage, the color of the square box changes to reflect current color.

To pick a color, press the right-click button on your mouse.

4. Go back to open the Color Picker menu, and you will see that it now reflects the color you’ve just selected. You can copy the Hex color code which is contained in the bottom rectangle box on the menu.

To apply this color to cells in your spreadsheet, simply paste the Hex code as explained in the copy and paste method.

📝 Note: Since Google Sheets is browser based, you can also follow these steps to pick and use colors from within your workbook.

Get the Hex Code from an Apps Script Custom Function

Apps Scripts are the way to automate tasks from within your Google Sheets, but they also allow you to create custom functions you can use in your workbook.

Go to the Extensions tab and choose Apps Script to open the script editor.

function GetColor(input) {
  var myFormula = SpreadsheetApp.getActiveRange().getFormula();
  var myAddress = myFormula.replace(/.*GetColor\(/gi, '').replace(/\).*/gi, '');
  var myRange = SpreadsheetApp.getActiveSheet().getRange(myAddress);
  return myRange.getBackgrounds();
 }

Copy and paste this script into your script editor and press the Save button. After you save it, go to your spreadsheet and refresh it.

The script creates a custom function named GetColor. The script uses the cell reference passed into the argument to get the background color of the cell and return the Hex code of the background color in that cell.

=GetColor(A1)

The custom formula has been used to get the Hex code of the background color of cell A1. When you compare it with the previously generated Hex codes, you will see they’re the same.

⚠️ Warning: This custom function relies on parsing the formula text to access the argument as a range and therefore needs to be entered exactly the same as found in the script.

Conclusions

Since hexadecimal color codes are standard across the web, you should get familiar with using them to apply colors to your spreadsheet.

This way you can be certain you’re using the same color variation in your projects even when it’s across many different applications.

Additionally, you can eliminate the burden of creating custom colors by using the Easy Color Picker extension to get suitable colors from external sources.

Do you know any other tips for finding the color hex code in Google Sheets? Let me know in the comments below!

About the Author

Oluwaseun Olatoye

Oluwaseun Olatoye

Oluwaseun is a business intelligence analyst with expertise in Google Sheets and SQL programming language. He has worked with various businesses to make data-driven decisions. He enjoys helping others learn and grow.

Related Articles

Comments

4 Comments

  1. Charles Forster

    If this helps anyone, I put together a Google Sheets template with all the hex codes for every color in the Google Sheets color picker: Google Sheets color picker template.

    • John MacDougall

      Cool! I’m sure it will help a lot of people who visit this post!

  2. Dylan

    Hi! How could I change the GetColor code to include a dummy variable so that the returned result will automatically refresh itself when the cell background color is changed?

  3. Morgan

    Hi,

    Do you have a solution to do the contrary ?
    I would like to add a list of hexa code and a cell between which will be colored.

Get the Latest Google Sheets Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in Google Sheets!