简体   繁体   English

将数据从工作表中的特定单元格复制到另一个工作表

[英]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.

相关问题 在工作表之间传输特定的单元格数据 - Transferring specific cell data from sheet to sheet 将特定数据从工作表复制到工作表 - Copy specific data from sheet to sheet 使用复选框将数据从特定单元格复制到另一个工作表(任务完成后变为 false) - To Copy data from specific cell to another sheet using a checkbox(turn false when task is done) Google Spreadsheet-如何将单元格数据从一张工作表复制到另一张工作表中的单元格? - Google Spreadsheet - How to copy cell data from one sheet to a cell in another sheet? Google Spreadsheet-脚本,每天在特定时间将单元格从一张工作表复制到另一张工作表 - Google Spreadsheet - Scripts, copy cell from one sheet to another sheet EVERYDAY at a specific time 根据单元格的值将一行数据从一个工作表复制到特定工作表的脚本 - script to copy a row of data from one sheet to a specific sheet based on the value of a cell Google文件-指令码,将储存格从一张工作表复制到另一张工作表 - Google Docs - Scripts, copy cell from one sheet to another sheet 将数据从一张纸复制到另一张电子表格,但不包括特定的列 - Copy data from one sheet to another spreadsheet exclude specific columns 根据特定的键值将数据从一张纸复制到另一张纸 - Copy data from one sheet to another based on a specific key value 如何将特定列的数据从一张表复制到另一张表 - How to copy specific columns of data from one sheet to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM