Edit background color

Here is a tip how to edit range’s background color.

 

Source code

function setBackgroundColor() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var color = "#1145ce";

  ss.getActiveRange().setBackground(color);

  var hd = "New Background Color: ";
  var nw = ss.getActiveRange().getBackground();

  Browser.msgBox(hd + nw);
}

 

Format

RangeObject.setBackground(color)

 

Parameters

color … Set the color code in string format.

 

Responses

None

 

It can also set color name to the parameter

function setBackgroundColor2() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var color = "blue";

  ss.getActiveRange().setBackground(color);

  var hd = "New Background Color2: ";
  var nw = ss.getActiveRange().getBackground();

  Browser.msgBox(hd + nw);
}

 

How to get a range’s object?

Please refer the following tips.

Get an active range object

Get a range object by row & column number

Get a range object by address

 

How to get range’s background color?

Please refer the following tip.

Get range’s background color

Leave a Comment