I am brand new to Google App Scripts. I have 1 google sheet, with 2 tabs. I have a timestamp script for each tab sheet. I can't figure out how to make it so that if someone types in a cell, a timestamp will automatically appear.
Thank you in advance for any help.
function onEdit(e){
myFunction1();
myFunction2();
function myFunction1(); {
var row = e.range.getRow();
var col = e.range.getColumn();
if(col === 15 && e.source.getActiveSheet().getName() === "Monthly Reviews" ){
e.source.getActiveSheet().getRange(row,16).setValue(new Date());
}
function myFunction2(); {
var s = SpreadsheetApp.getActiveSheet();
if( s.getName() == "SLP" ) { //checks that we're on "TABNAME" tab or not
var r = s.getActiveCell();
if( r.getRow() == 7 && r.getColumn() == 2 ) { // checks that the cell being edited is in row 7 column
2
var nextCell = r.offset(1, 0); // looks at the cell in the 1 row down same column
if( nextCell.getValue() === '' ) // checks if that adjacent cell (1 down) is empty or not?
nextCell.setValue(new Date()).setNumberFormat('MM-dd-yyyy HH:mm:ss'); //sets the timestamp when
original cell is updated
}
}
}
}
function onEdit(e){
var row = e.range.getRow(),
col = e.range.getColumn(),
tmshtCell = null;
switch (e.source.getActiveSheet().getName()){
//checks that we're on "TABNAME" tab or not
case 'Monthly Reviews' :
if (col === 15) tmshtCell = e.range.offset(0,1)
break;
//checks that we're on "SLP" tab or not
case 'SLP':
// checks that the cell being edited is in row 7 column 2 and checks if that adjacent cell (1 down) is empty or not?
if (row === 7 && col === 2 && e.range.offset(1,0).getValue() == '') tmshtCell =e.range.offset(1,0)
break;
}
if (tmshtCell) tmshtCell.setValue(new Date()).setNumberFormat('MM-dd-yyyy HH:mm:ss')
}
function onEdit(e) {
const sh = e.range.getSheet();
if (sh.getName() == "Monthly Reviews" && e.range.columnStart == 15) {
e.range.offset(0, 1).setValue(new Date());
}
if (sh.getName() == 'SLP' && e.range.columnStart == 2 && e.range.rowStart == 7) {
if (e.range.offset(1, 0).getValue() == '') {
e.range.offset(1, 0).setValue(new Date());
}
}
}
Note: You cannot run this function from the script editor unless you supply the event object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.