更改另一个单元格时,在单元格中输入当前日期 [英] Enter current date into a cell when another cell is changed

查看:92
本文介绍了更改另一个单元格时,在单元格中输入当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google电子表格,可用来跟踪从客户端请求的应用程序配置信息的状态.例如.要在按钮上输入文字. 我有一列的顶部是状态",而下面的行中的单元格是来自范围的列表"数据验证.使用的范围包括与客户",与我",已完成".我在右侧还有一列,该列用于在上次更改状态时手动添加日期.我想要的是将日期自动更改为今天的日期(当我更改状态时).我相信可以使用脚本来完成,但是我以前从未使用过.

I have a Google spreadsheet that I use to track the status of configuration information requested for an app, from a client. E.g. Text to go on a button. I have a column with 'Status' at the top and cells with 'List from Range' Data Validation in the rows beneath. The range used has 'With client', 'With Me', 'Completed'. I also have a column to the right which I use to manually add the date the last time the status changed. What I would like is for the date to be automatically changed to today's date when I change the status. I believe it can be done with a script but I have never used one before.

推荐答案

另一个答案从一个好主意开始,但是不幸的是,建议的代码不起作用,因为它有很多基本错误(显然,它没有经过测试……)

The other answer started with a good idea but unfortunately the suggested code does not work because it has many basic errors (obviously it wasn't tested ...)

所以这是一个简单的版本:

So here is a version that simply works :

function onEdit(e) {
  var sheet      = e.source.getActiveSheet();
  var activeCell = sheet.getActiveCell();
  var col        = activeCell.getColumn();
  var row        = activeCell.getRow();
  if (col == 2 ) { // assuming status is in column 2, adapt if needed
    sheet.getRange(row, col+1).setValue(new Date()).setNumberFormat('MMM dd yyyy');// change the display format to your preference here
  }
}

这篇关于更改另一个单元格时,在单元格中输入当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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