简体   繁体   English

将基于单元格值的行数据复制到 Google 表格中的新工作表

[英]Copy row data based on cell value to new sheet in Google Sheets

I would like to make an Apps Script to allow a row of data to be copied to another sheet for "history".我想制作一个应用程序脚本,以允许将一行数据复制到另一张“历史记录”表中。

I have tried several different scripts.我尝试了几种不同的脚本。 While some have sort of worked, ultimately, they quit functioning for some reason.虽然有些工作,但最终,由于某种原因,他们退出了工作。 Also, they did not have the completeness I wanted.此外,它们没有我想要的完整性。

I want a checkbox to be selected and then a selection made from the custom UI button.我希望选中一个复选框,然后从自定义 UI 按钮中进行选择。 Upon clicking the Copy Data button, the row data that contains the checkbox, needs to be copied to the new sheet.单击“复制数据”按钮后,需要将包含复选框的行数据复制到新工作表中。 After the data is copied, I would like a function to delete the row(s), but not formulas, that have a checkmark in them.复制数据后,我希望 function 删除其中有复选标记的行,但不是公式。 This would preferably be made as another button in the custom UI menu.最好将其设置为自定义 UI 菜单中的另一个按钮。

Column A holds employee names. A 列包含员工姓名。 Column B autofills current date when Column A sees input from dropdown.当 A 列从下拉列表中看到输入时,B 列会自动填充当前日期。 Column C holds the checkbox. C 列包含复选框。 Column D is generic work list. D 列是通用工作清单。

Is something like the following what I need?我需要以下类似的东西吗?

 function onOpen(e) { let ui = SpreadsheetApp.getUi(); ui.createMenu('PAS Data').addItem('Copy Data', 'copyData').addToUi(); } function copyData() { var ss=SpreadsheetApp.getActive(); var sheet=SpreadsheetApp.getActiveSheet(); var range=sheet.getActiveCell(); if (sheet.getName()=="ShopWorkList" && range.getColumn()==3 && range.getValue()=="TRUE") { var targetSheet=ss.getSheetByName("Sheet2"); var targetRange=targetSheet.getRange(targetSheet.getLastRow() + 1, 1);//column one sheet.getRange(range.getRow(), 1, 1, sheet.getLastColumn()).moveTo(targetRange); sheet.deleteRow(range.getRow()); } }

https://docs.google.com/spreadsheets/d/e/2PACX-1vRre5h3CQDhydswUi7NOBRld2j3PmOldBjXqZmjazBaTBkFRDWn6N_uFPEO8enA6LAiLCwhMoeQ8Tdr/pubhtml https://docs.google.com/spreadsheets/d/e/2PACX-1vRre5h3CQDhydswUi7NOBRld2j3PmOldBjXqZmjazBaTBkFRDWn6N_uFPEO8enA6LAiLCwhMoeQ8Tdr/pubhtml

Try it this way:试试这种方式:

function copyData() {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName("ShopWorkList");
  const osh = ss.getSheetByName("Sheet2");
  const vs = sh.getRange(17, 1, sh.getLastRow() - 16, sh.getLastColumn()).getValues();
  let oA = [];
  let d = 0;
  vs.forEach((r, i) => {
    if (r[2] == true) {
      oA.push(r);
      sh.deleteRow(i + 17 - d++);
    }
  });
  if (oA.length > 0) {
    osh.getRange(osh.getLastRow() + 1, 1, oA.length, oA[0].length).setValues(oA);
  }
}

暂无
暂无

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

相关问题 根据条件和单元格值将行复制到 Google 表格上的另一张表格 - Copy row to another sheet on Google Sheets based on criteria and cell value 根据单元格中的值将行复制到新工作表 - Copy a row to new sheet based on value in a cell 根据行中单元格中的值将特定行复制到新的Google工作表(JavaScript) - Copy a specific row to new google sheet based on value in a cell in the row (JavaScript) 我想根据前一行的单元格中的某些单元格值复制谷歌工作表中下一行的数据 - I want to copy data in next rows in google sheet based upon certain cell value in a cell of the Preceding row Google Sheets - 根据下拉值将行移动到新工作表 - Google Sheets - Move row to new sheet based on drop down value 如何更新 Google 表格中特定行的单元格(基于 Json 数据)使用 google apps 脚本创建新的 Jira 问题和更新表格 - How to update cell of a particular row in Google Sheets (based on Json data) using google apps script to create a New Jira issue and update sheet Google Sheets onEdit - 尝试通过更改同一行中列的值将一行复制到新工作表 - Google Sheets onEdit - trying to copy a row to a new sheet by changing the value of a column within that same row 根据单元格的 function 值将行移动到新工作表 - Google 表格 - Move row to new sheet base on cell's function value - Google Sheets Google表格:根据单元格值将行移至其他表格,然后再次返回 - Google Sheets: Move Row to Other Sheet, Then Back Again, Based on Cell Value 根据单元格的值将一行数据从一个工作表复制到特定工作表的脚本 - script to copy a row of data from one sheet to a specific sheet based on the value of a cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM