I have text in cell E9. I want to have the text and color change and code execute when click on cell. I have not put any code in yet, just testing for now.I have the following script which should change the text and color in cell E9 when clicked, and then move the cursor to cell A1:
function onSelectionChange(e) {
const range = e.range;
const sheet = range.getSheet();
const a1Notation = range.getA1Notation();
if (a1Notation == "E9") {
if (range.getValue() == "SHOW Guidelines") {
range.setBackground("#ff0000");
range.setValue("HIDE Guidelines");
} else {
range.setBackground("#38761d");
range.setValue("SHOW Guidelines");
}
}
sheet.getRange("A5").activate();
console.log("test2")
}
When I click on cell E9, the value of the cell changes with the color, as it should. The execution log shows “test2”,so I now it executed past the prior line, but the active cell is still E9 (it did not move to A1 as would be expected). Is there something I am missing? Or any suggestions on another method?