Google Sheets OnEdit 脚本:从特定列复制值

亚伦史密斯

我们正在使用 Google 表格来跟踪出勤情况。以前,教师为每个时段输入 P、T 或 A(表示出席、迟到、缺席)。我仍然希望用户可以选择为一周中的每个时间段输入一个值,但是如果他们可以为一整天输入一个值,那将是一个很好的节省时间。

我想要的是,如果将值输入到带有“P”或“A”(数据验证限制这些选项)的“0”句点(绿色列)中的任何一个,OnEdit函数将复制相同的字母( "P" 或 "A") 到以下 8 列,然后删除原始值(如果不删除,最右侧列的总数将关闭)。我不希望基于任何非绿色列中的编辑激活 OnEdit

我最终会有几个标签,每个标签都在不同的一周,但每个都完全相同......所以我认为该功能应该在活动表中的任何内容中工作。

https://docs.google.com/spreadsheets/d/1NKIdNY4k66r0zhJeFv8jYYoIwuTq0tCWlWin5GO_YtM/edit?usp=sharing

感谢您的帮助,

乔丹·瑞亚

我写了一些代码来帮助你开始你的项目。(我也是一名老师)您将不得不根据您的目标进行一些更改,并且可能可以对其进行优化以运行得更快。祝你好运!

function onEdit(e) {

  //create an array of the columns that will be affected
  var allColumns = [2, 10];

  //get the number values of the column and row
  var col = e.range.getColumn();
  var row = e.range.getRow();

  //get the A1 notation of the editted cell for clearing it out
  var cell = e.range.getA1Notation();

  //only run if the cell is in a column in the allColumns array
  if(allColumns.indexOf(col) > -1) {

    //run the for loop for the next 8 cells
    for(var i = col + 1; i < col + 9; i++) {
      SpreadsheetApp.getActiveSheet().getRange(row, i).setValue(e.value);
      SpreadsheetApp.getActiveSheet().getRange(cell).setValue('');
    }
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Google Sheets onEdit 没有通过复制和粘贴触发

Google Sheets 脚本 onEdit() + 复选框验证

Google Sheets OnEdit()-您无权调用showModalDialog

Google Sheets OnEdit() - 您无权调用服务

Google Apps脚本:onEdit

Google Sheets onEdit - 尝试通过更改同一行中列的值来将一行复制到新工作表

Google Form + Apps脚本onEdit

Google Sheets onEdit(e) 动态排序功能

特定列的 Google Apps 脚本 onEdit(e) 不起作用

Google表格onEdit大写脚本功能

Google App脚本onedit仅限工作表

基于 onedit / google 表格的调用脚本

Google表格脚本可隐藏无法在onEdit()上使用的列

Google Sheets 使用 onEdit 函数创建随机单元格边框

在 1 个主 onEdit 下运行太多 onEdit 脚本?GoogleSheets / Google Apps 脚本

在Google脚本的Google脚本内的特定工作表上使用onedit()触发器

Google Apps脚本onEdit()无法访问外部API?

Google表格脚本onEdit的表单响应清除单元格

我需要在 onEdit 中运行 Google App 脚本

适用于 Google 表格的 Apps 脚本(onedit 功能)

Google Doc Script onEdit

Google表格onEdit计算

OnEdit不会在Google App脚本中通过复制和粘贴触发

如果列是 Today(),Google Sheets 如何获取特定行的值?

与多列相关的 Google Sheets 脚本

Google Sheets脚本循环问题

Google Apps脚本:onEdit在SpreadsheetApp.openById()上中断-需要在可安装的onEdit()触发器上输入

Gmail onEdit Apps 脚本,

Google Sheets APP 脚本:以特定的分隔字符导入 CSV