0
votes

I want to get return cell background color in a google script. The current function looks like

function BGColor(colorref) {
var sheet = SpreadsheetApp.getActiveSheet();
Logger.log(sheet.getRange(colorref).getBackground());
var color = sheet.getRange(colorref)
    .getBackground();
return color;
}

Currently colorref must be a string, which means that the cell input on the spreadsheet side of things is like =BGColor("C2"). But this means that I must manually input what goes into the function, instead of just the cell values, which would look like = BGColor(C2).

How can I extract the name C2 from cell C2 instead of its value, which is some number.

1

1 Answers

1
votes

You may be looking for something like

=bgcolor(cell("address",D2))

(note: depending on your locale you may have to change the comma to a semi colon).

Your script can also be simplified to;

function BGColor(colorref) {
return SpreadsheetApp.getActiveSheet().getRange(colorref).getBackground();
}