Completely new when it comes to scripting etc but managed to get some small scripts working via looking up things here and there, so please bear with me.
I am looking to create a script that allows me to enter a value in a cell in sheet1 that adds the value to a cell in sheet2 (so not a simply copy over). Once the value in sheet1 has been entered, it clears itself.
Sadly, I have no script to show you of what I have tried, as this has me completely stumped. If anyone has any pointers or can provide help, it would be much appreciated.
Edit:
Based on below code, I've tried something like this:
function onEdit(e) {
//e.source.toast('Entry');//used for debugging
//Logger.log(JSON.stringify(e));//get event object
const sh = e.range.getSheet();
if(sh.getName() == "Dashboard" && e.getRange("C17") && e.value) {
let rg = e.source.getSheetByName("Data").getRange("D2")
rg.setValue(Number(rg.getValue()) Number(e.value));
e.range.setValue('');
}
}
Though not getting it to work.
CodePudding user response:
Add B2 Sheet0 to B2 Sheet1
function onEdit(e) {
//e.source.toast('Entry');//used for debugging
//Logger.log(JSON.stringify(e));//get event object
const sh = e.range.getSheet();
if(sh.getName() == "Sheet1" && e.range.columnStart == 2 && e.range.rowStart == 2 && e.value) {
let rg = e.source.getSheetByName("Sheet2").getRange(e.range.rowStart,e.range.columnStart)
rg.setValue(Number(rg.getValue()) Number(e.value));
e.range.setValue('');
}
}
Note: you cannot run this type of function from the script editor just paste into script editor, save and go to Sheet1 B2 and type in a number and hit return. Then look on Sheet2 to see B2 change.