特定单元格包含文本"YES"时的自动日期



我正在寻找有关此代码的帮助:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Trip Overview" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 12 ) { //checks the column
      var nextCell = r.offset(0, 15);
      //if( nextCell.getValue() !==  ) //is empty?
      nextCell.setValue(new Date());
    }
  }
}

如果第12列包含任何值,1,2,3或"是"," adf"," no"等,代码当前正在添加日期。

如果单元12包含"是"?

,如何修改此代码才能添加日期

检查您是否在正确的表格和列中,您需要检查单元格的值是否为"是"

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Trip Overview" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 12 ) { //checks the column
      if(r.getValue() == "YES") { //checksthe value of the cell
        var nextCell = r.offset(0, 15);
        nextCell.setValue(new Date());
      }
    }
  }
}

最新更新