简体   繁体   English

根据单元格的值将一行数据从一个工作表复制到特定工作表的脚本

[英]script to copy a row of data from one sheet to a specific sheet based on the value of a cell

I'm trying to create a script to copy a row of data from one sheet to a another sheet based on the value of a cell.我正在尝试创建一个脚本来根据单元格的值将一行数据从一个工作表复制到另一个工作表。

But essentially when a new row of information is input in the main sheet it'll copy the row and place that row of data into a another sheet based off the value of a specific cell.但本质上,当在主工作表中输入新的信息行时,它将复制该行并将该行数据放置到基于特定单元格的值的另一个工作表中。 In this case it's the utility company.在这种情况下,它是公用事业公司。 If, for example, the customer is created and the utility company they have is United Power I want to have the sheet copy that customers information over and add it to the specified United Power sheet and so on and so forth with the other utility company's (3 total)例如,如果创建了客户并且他们拥有的公用事业公司是 United Power 我希望拥有客户信息的表格副本并将其添加到指定的 United Power 表格中,依此类推,其他公用事业公司的 (共 3 个)

I keep getting the below error: TypeError: Cannot read property 'source' of undefined (line 4, file "Code")我不断收到以下错误:TypeError:无法读取未定义的属性“源”(第 4 行,文件“代码”)

I'll paste below what I have so far.我将粘贴到目前为止。 (I only have the code for one so far) I can also link the spreadsheet if need be. (到目前为止,我只有一个的代码)如果需要,我还可以链接电子表格。

 function onEdit(event) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s = event.source.getActiveSheet();
  var r = event.source.getActiveRange();

  if(s.getName() == "Contracts" && r.getColumn() == S && r.getValue() == "United Power") {
  
    var row = r.getRow();
    var numColumns = s.getLastColumn();
    var targetSheet = ss.getSheetByName("United Power");
    var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    s.getRange(row, 1, 1, numColumns).moveTo(target);
  } 
}

You could have written like this:你可以这样写:

You need to change S to a number您需要将 S 更改为数字

function onEdit(e) {
  const sh=e.range.getSheet();
  if(sh.getName()=="Contracts" && e.range.columnStart==19 && e.value=="United Power") {
    const tsh = e.source.getSheetByName("United Power");
    const target = tsh.getRange(tsh.getLastRow() + 1, 1);
    sh.getRange(e.range.rowStart,1,1,sh.getLastColumn()).moveTo(target);
  } 
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 根据特定的键值将数据从一张纸复制到另一张纸 - Copy data from one sheet to another based on a specific key value 将基于单元格值的行数据复制到 Google 表格中的新工作表 - Copy row data based on cell value to new sheet in Google Sheets 根据单元格中的值将行复制到新工作表 - Copy a row to new sheet based on value in a cell 用于根据条件将数据从一张纸复制到另一张纸的脚本 - Script to copy data from one sheet to another based on criteria 根据单元格值将最后一行从一个工作表复制到另一个工作表,并在主工作表中不断更新 - Copy last row from one sheet to another depending on cell value with constant updates in master sheet 将数据从工作表中的特定单元格复制到另一个工作表 - copy data from specific cell in a sheet to another sheet 根据行中单元格中的值将特定行复制到新的Google工作表(JavaScript) - Copy a specific row to new google sheet based on value in a cell in the row (JavaScript) 谷歌脚本将数据从工作表 1 复制到第一个空行工作表 2 - google script copy data from sheet 1 to first empty row sheet 2 我想根据前一行的单元格中的某些单元格值复制谷歌工作表中下一行的数据 - I want to copy data in next rows in google sheet based upon certain cell value in a cell of the Preceding row Google 工作表应用程序脚本 - 根据循环条件将数据从一张工作表复制到另一张工作表 - Google sheet app script - Copy data from one sheet to another based on condition with loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM