Hi there,
I am looking to make a script that allows me to format a target cell if in my reference range there is a cell with a specific background color.
So if a cell in my range 'A1:E1' has a red background, then 'F1' takes on the value 'ALERT' with a red font. Otherwise, 'F1' evaluates to 'OK' with a green font.
The following code does not work :
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
const red = '#ff0000';
const green = '#00ff00';
var referenceRange = sheet.getRange('A1:E1');
var rangeColor = referenceRange.getBackgroundColor();
var targetRange = sheet.getRange('F1');
if (rangecolor === red)
{
targetRange.setFontColor(red).setValue('ALERTE')
}
else
{
targetRange.setFontColor(green).setValue('OK')
};
The problem is that I'm only getting the background color of cell 'A1'.
If I put a red background in A1, it gives me in 'F1': "ALERT";
On the other hand, if there is no red in A1 but there is in the other cells of the range, it gives me in 'F1': "OK".
I tried with getBackgroundColors => 'F1' always returns: "OK" in every case.
Basically, I would like that from the moment there is a red cell in the range, it returns me "ALERT" in 'F1'.
<can you help me ?