On sheet1 there is a submit button which runs a script and moves data into sheet2.
I'm 'timestamping' the move (under certain conditions to prevent overwriting, and pointless timestamps), however with the current script—
Issue (1): onEdit only takes place if I manually make an edit on sheet2 (=sheet2 is active).
RESOLVED! (See comments) Issue (2): onEdit won't restrict to sheet2, and will happen as well on sheet1.
function onEdit() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
if( sheet.getName() == "sheet2" ) {
var activecell = sheet.getActiveCell();
if( activecell.getColumn() == 2 ) {
var pastecell = activecell.offset(0, -1);
if( pastecell.getValue() === '' & activecell.getValue() != '' )
pastecell.setValue(new Date()).setNumberFormat('YY-MM-DD HH:mm:ss');
}
}
}
Anyone know how two fix this?
Your help and insight is much appreciated!
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
to:var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet
– saadya