I'm trying to use an if statement in scripts to set cell values once conditions are met, however its not working and i can't figure out why.
I need to do it using scripts rather than formulas in the sheet itself
var mainWSname = "Exposure"
function onEdit(e){
var activeCell = e.range();
var r = activeCell.getRow()
var c = activeCell.getColumn()
var val = activeCell.getValue();
var wsName = activeCell.getSheet().getName()
if(wsName === mainWSname && c === 2 && val === "Match"){
wsName.getRange(r, 3).setValue("18")
wsName.getRange(r, 4).setValue("80")
}
}
CodePudding user response:
Try this modification:-
var mainWSname = "Exposure"
function onEdit(e){
var activeCell = e.range;
var r = activeCell.getRow()
var c = activeCell.getColumn()
var val = e.value;
var wsName = activeCell.getSheet()
if(wsName.getName() === mainWSname && c === 2 && val === "Match"){
wsName.getRange(r, 3).setValue("18")
wsName.getRange(r, 4).setValue("80")
}
}
Reference: