Home > Mobile >  I need help to Timestamp specific tabs in a sheet
I need help to Timestamp specific tabs in a sheet

Time:07-28

Here is the current script I have written in App Script to timestamp but i need to be able to timestamp specific tabs in a doc:

function TIMESTAMPOACStart(e) {
  var row = e.range.getRow();
  var col = e.range.getColumn();
  if (col == 4) {
    e.source.getActiveSheet().getRange(row,5).setValue(new Date());
  }
}

What do i need to edit to get this correct?

CodePudding user response:

Look in google documentation and you can see all you need which is specifically getsheetByName().

So ultimately something like this...

function TIMESTAMPOACStart(e) {
  var row = e.range.getRow();
  var col = e.range.getColumn();
  var yourSheetName = "sheet3"// <-- or whatever sheet name you want to apply to.
  var mySheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(yourSheetName);

  if (col == 4) {
    mySheet.getRange(row, 5).setValue(new Date());
  }
}

CodePudding user response:

Try this:

function TIMESTAMPOACStart(e) {
  const sh = e.range.getSheet();
  const shts = ['Sheet1', 'Sheet2'];//only works on these sheets
  const idx = shts.indexOf(sh.getName());
  if (~idx && e.range.columnStart == 4) {
    sh.getRange(e.range.rowStart, 5).setValue(new Date()); 
  }
}
  • Related