I want to use the onSelectionChange trigger twice. When I select a cell the cell's background changes to blue. But when I select another cell, I would like for the previous cell's background to change from blue to red, but the current cell to change to blue.
I can get the current cell change to blue, but am unable to get them to red once I am no longer selecting them
I have 2 separate functions and I tried to give them different variable input arguments, but I'm not sure how to get them to work together.
function onSelectionChange(e) {
rangeE = e.range;
if (rangeE.getColumn() <= 5) {
if (rangeE.getNumRows() === 1 &&
rangeE.getNumColumns() === 1 &&
rangeE.getCell(1, 1).getValue() !== '') {
oldCell = rangeE.getCell(1, 1)
rangeE.setBackground('blue');
}
}
}
function onSelectionChange(q) {
const rangeQ = q.range;
currentCell = rangeQ.getCell(1, 1)
if (currentCell !== oldCell){
if (rangeQ.getColumn() <= 5) {
if (rangeQ.getNumRows() === 1 &&
rangeQ.getNumColumns() === 1 &&
rangeQ.getCell(1, 1).getValue() !== '') {
rangeE.setBackground('red');
}
}
}
}