Home > front end >  Isolate script to one tab in Google Sheets
Isolate script to one tab in Google Sheets

Time:01-13

I've tried searching for the answer I need, but I can't seem to get this to work on my google sheet.
Ideally, I want to click a checkbox in Column A on the sheet "CertInfo" and have it print the date in the cell next to it. Unfortunately, it seems to be doing this on every single tab no matter what I try. I don't really know anything about scripting besides blindly cobbling together bits of code from here and there, but I've finally given up here. I just don't understand how these variables interact.

function onEdit(e) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("CertInfo");
  var r = sheet.getActiveCell();
    if( r.getColumn() == 1 ) { 
      var nextCell = r.offset(0, 1);
      var newDate = Utilities.formatDate(new Date(), 
      ss.getSpreadsheetTimeZone(), "MM/dd/yyyy");
      nextCell.setValue(newDate);
   }
}

Hopefully this post has enough information.
It would also be nice if it only checked to see if the check box was "True" and not "on edit" but I can accept that as beyond me.

CodePudding user response:

Write to one sheet

function onEdit(e) {
  const sh = e.range.getSheet();
  if(sh.getName() == "CertInfo" && e.range.columnStart == 1) {
    e.range.offset(0,1).setValue(new Date()).setNumberFormat("MM/dd/yyyy");
  }
}
  •  Tags:  
  • Related