[英]Return a value to a cell in google spreadsheet with an onEdit trigger
I'm basically trying to make a script that when cell C4
is changed or edited then it will return the variable "date" to cell L4
. 我基本上是想制作一个脚本,当更改或编辑单元格
C4
时,它将把变量“ date”返回到单元格L4
。
function onEdit(e) {
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var date = Utilities.formatDate(new Date(), "GMT+1", "yyyy/MM/dd");
var cellAddress = e.range.getA1Notation();
if ( CellAdress === 'C4' ) {
var range = sheet.getActiveSheet().getRange('L4');
var nrange = sheet.setActiveRange(range);
nrange = date
}
}
I know that the last part doesn't work, but I can't get my head around how to properly use the functions, been searching for a while but can't find anything related precisely to making the function change the cell. 我知道最后一部分不起作用,但是我无法了解如何正确使用这些功能,已经搜索了一段时间,但是找不到与使功能更改单元格完全相关的任何内容。
Please note this function is called whenever any edit is made on any sheet. 请注意,在任何工作表上进行任何编辑时,都会调用此函数。 Since this function does not specify a sheet, then an edit of cell C4 on any sheet will set the value of L4 on on that sheet.
由于此函数未指定工作表,因此在任何工作表上对单元格C4进行编辑都会在该工作表上设置L4的值。 So I would recommend that you add some sheet restrictions as shown in the comments.
因此,我建议您添加一些工作表限制,如注释中所示。
function onEdit(e) {
var rg=e.range;
var sh=rg.getsheet();
var row=rg.getRow();
var col=rg.getColumn();
if(col==3 && row==4){//Page Restrictions Added: if(sh.getName()=='sheetname' && col==3 && row==4){
sh.getRange(4,12).setValue(Utilities.formatDate(new Date(), "GMT+1", "yyyy/MM/dd"));
}
}
I saw your answer (Write new Date() string to L4 when C4 is edited on any Sheet). 我看到了您的答案(在任何工作表上编辑C4时,将新的Date()字符串写入L4)。 I try with my programm, but it doesn't work.
我尝试使用我的程序,但没有用。 My programm is the following :
我的程序如下:
function onedit(e) {
var valeur_1=1;
var rg=e.range;
var sh=rg.getsheet();
var row=rg.getRow();
var col= rg.getColumn();
if(col==1 && row==1) {
sh.getRange(2,1).setValue(valeur_1);
}
I wanted try with a simple programm, If I understand well, if the value in A1 change then I will obtain the value Valeur_1 in cell A2, it is all right ot not?? 我想尝试一个简单的程序,如果我很好理解,如果A1中的值发生变化,那么我将在单元格A2中获得值Valeur_1,这可以吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.