2 Ways to Color Cells in Google Sheets

This post is going to show you step-by-step how to change the color of a cell in Google Sheets.

Have you ever come across a situation where you wanted to change the cell color to distinguish it from all others?

You might wish to change your column headers to a different color, or you might want to make the cells appear red to flag them as non-editable cells.

For such cases, you need to know how you can change the cell background color to one of your choices.

If that sounds like something exciting and needed at your work, then read on!

Color a cell from the Toolbar

To change the cell color, using the Toolbar Fill Color functionality is the most popular option.

You can change the color without much hassle with the toolbar command. The Toolbar holds several quick features such as Undo, Redo, Font, Font Size, Text Color, etc.

Follow these steps to change the cell color.

  1. Select the cells which you want to change the color.
  2. Click on the Fill Color icon in the Toolbar.
  3. Select a color option.

In the far right of the Toolbar is for Fill Color. It’s the icon of a paint bucket with color pouring out.

Click on it, and you will see a list of colors you can choose from to apply to your cell background, as shown in the screenshot above.

There are many preset colors available, but you can also create your own custom colors. Click on the Plus icon found under the CUSTOM label to create a custom color option.

This will open a color picker menu and you can either input the hex code for the desired color or select the color from the interface. Press the OK button to save your selection.

You will see that the cells are colored now in the color of your choice!

Piece of cake! Right? It is indeed an easy method to change cell colors.

Color a cell with Apps Script

Another method to change cell color is with the Apps Script! This tool allows you to automate the day-to-day boring stuff using a few lines of JavaScript code in the Google Sheets environment.

If you are not familiar with Apps Scripts, you can read up on it more with The Beginners Guide to Apps Scripts in Google Sheets.

You can use Apps Script to write your own small piece of code that can automate the task of coloring a cell or range in Google Sheets.

Go to the Extensions menu and select the Apps Script option. This will launch the editor in a new browser window.

Copy and paste the following code inside the Apps Script editor to change the background color of a cell in Google Sheets.

function changeBackgroundColor() {
  var ss = SpreadsheetApp.getActiveSheet()
  var range = ss.getRange("A1:A3");
  range.setBackground("red");
};

Explanation

  • Every code in Apps Script is a function. The function keyword defines the function, and you can name it anything you’d like. However, a descriptive name is always a better choice. This function was named as changeBackgroundColor().
  • You first need to decide the sheet you want to change the cell color in. The SpreadSheetApp.getActiveSheet() method gives you the currently active worksheet. The result is stored in a variable named ss.
  • You need to decide the range you want to change color. In this example, the range "A1:A3" will be changed. Therefore, the getRange() method is used to fetch that range, and the result is stored in the variable named range.
  • Finally, the setBackground() method is called upon the range defined, and the cell color is set to "red". You can set any other color here.

Once you are done with the code, hit the Run button that is placed on the horizontal Toolbar in the Apps Script.

It will run the code, and the Execution log shows you the progress made. Once the Execution log is complete, you can go back and check your Sheet. The cells A1:A3 will be colored red.

Conclusions

There are two ways to change the color of cells in Google Sheets.

The Toolbar has a Fill Color option that can change the cell color to one of your choices in Google Sheets.

Apps Script allows you to write a code of your own that can change the cell color as well.

Do you know any other methods apart from these two to change the cell colors? Let me know through the comment section!

About the Author

Lalit Salunkhe

Lalit Salunkhe

Lalit is a data analyst with diverse skills and experience in data mining and analysis. He has a M.Sc. in Statistics from one of the top institutes in Maharashtra. Lalit is also a Google Sheets expert and enjoys teaching others how to use Google Sheets to solve their data problems.

Related Articles

Comments

1 Comment

  1. Ryan Waris

    Hello there

    I had a question. If I have enabled conditional formatting on a cell (lets say A1). The colour changes from green to red if value is from 0 to 100. Now I want the cell A2 to have same colour as A1, despite what i write in A2. How can I do that in script??

    Do I change “red” to “A1”?

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!