其他列更改时,将时间戳添加到一列 [英] Add a timestamp to one column when other columns changed

查看:147
本文介绍了其他列更改时,将时间戳添加到一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果只有一列是下面的脚本,那么这个脚本就可以工作了。更改,但不是多列。

  function onEdit(){
var s = SpreadsheetApp.getActiveSheet();
if(s.getName()==Allocation Requests){//检查我们是否在正确的表单上
var r = s.getActiveCell();
if(r.getColumn()== 7){//检查列
var nextCell = r.offset(0,7);
nextCell.setValue(new Date());
}
}
}

这样如果列E,F,G或H发生更改,列M中的时间戳就会更新。谢谢

解决方案

也许这会起作用

  function onEdit(){var s = SpreadsheetApp.getActiveSheet(); if(s.getName()==Sheet1){//检查我们是否在正确的表单上var r = s.getActiveCell();如果(r.getColumn()== 5){//检查列var nextCell = r.offset(0,8); nextCell.setValue(new Date()); } if(r.getColumn()== 6){//检查列var nextCell = r.offset(0,7); nextCell.setValue(new Date()); } if(r.getColumn()== 7){//检查列var nextCell = r.offset(0,6); nextCell.setValue(new Date()); } if(r.getColumn()== 8){//检查列var nextCell = r.offset(0,5); nextCell.setValue(new Date()); }}}  


I'm trying to add a timestamp to a column when other cells in the same row are completed or changed.

The below script works if just one column is changed, but not multiple columns.

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Allocation Requests" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 7) { //checks the column
      var nextCell = r.offset(0, 7);
          nextCell.setValue(new Date());
      }
  }
}

I'm trying to get it so that if columns E,F,G or H are changed, the timestamp in Column M is updated. Thanks

解决方案

Perhaps this will work

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
    var r = s.getActiveCell();
    if( r.getColumn() == 5) { //checks the column
      var nextCell = r.offset(0, 8);
          nextCell.setValue(new Date());
      }
       if( r.getColumn() == 6) { //checks the column
      var nextCell = r.offset(0, 7);
          nextCell.setValue(new Date());
      }
       if( r.getColumn() == 7) { //checks the column
      var nextCell = r.offset(0, 6);
          nextCell.setValue(new Date());
      }
       if( r.getColumn() == 8) { //checks the column
      var nextCell = r.offset(0, 5);
          nextCell.setValue(new Date());
      }
  }
}

这篇关于其他列更改时,将时间戳添加到一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆