[英]copy data from specific cell in a sheet to another sheet
There are few queries which are somewhat similar but I'm unable to get a solution from those.很少有类似的查询,但我无法从中获得解决方案。
In my mainsheet I'm importing data from a webpage using Importdata function in the mainsheet.在我的主表中,我使用主表中的 Importdata 函数从网页导入数据。 The data in the webpage changes every 5mins and so the cell value A50 changes every 5 mins in the mainsheet.网页中的数据每 5 分钟更改一次,因此主表中的单元格值 A50 每 5 分钟更改一次。
Now I want to write a google app scrip function that will copy the value from A50 of mainsheet to another sheet in the cell A1,A2,A3,A4,A5.......and so on and have a timestamp correspondingly in B1,B2,B3,B4,B5....and so on现在我想编写一个谷歌应用程序脚本函数,它将主表的 A50 中的值复制到单元格 A1、A2、A3、A4、A5......等中的另一个工作表,并在其中相应地有一个时间戳B1,B2,B3,B4,B5....等等
You can use onEdit()
trigger function to do this.您可以使用onEdit()
触发器函数来执行此操作。 When an edit happens in cell A50
check if cell and sheets are correct then read value and save into target sheet.当单元格A50
发生编辑时,检查单元格和工作表是否正确,然后读取值并保存到目标工作表中。 Below code does that.下面的代码就是这样做的。 Change the sheet names as shown in comment.更改工作表名称,如注释中所示。
function onEdit(e) {
// check if active range is A50 or not
var rangeStr = e.range.getA1Notation();
if (rangeStr != 'A50') return;
// get Spreadsheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
// get sheets
var mainSheetNames = ['main sheet name', 'main sheet name', 'main sheet name']; // change here
var mainSheet = e.range.getSheet();
if (mainSheetNames.indexOf(mainSheet.getName()) == -1) return;
var targetSheet = ss.getSheetByName('target sheet name'); // change here
// get value
var value = e.value;
// set values
targetSheet
.getRange(targetSheet.getLastRow() + 1, 1, 1, 2)
.setValues([[value, new Date().toLocaleString()]]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.