Google表格将行复制并粘贴到另一张表格中,然后从第一张表格中删除内容 [英] Google Sheets copy and paste row into another sheet and then delete content from the first sheet

查看:91
本文介绍了Google表格将行复制并粘贴到另一张表格中,然后从第一张表格中删除内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2张纸,列数相同,所有列的标题均相同。当项目为就绪时,我希望能够在该行的数据验证中选择就绪,并将该行复制到项目表中,然后从预测项目表中删除该行。如果只可以从预测表上该复制的行中擦除内容,然后将其下面具有内容的所有其他行上移,则更合适。

I have 2 sheets with an identical number of columns and all the columns have identical headers. When a project is "ready" I want to be able to select "Ready" in a data validation in that row and have that copy that row over to the Projects sheet and remove that row from the Forecasted Projects sheet. I would prefer if the contents only could be wiped from that copied row on the forecast sheet and then all other rows below it that have content could be moved up.

原样,该脚本将从预测的项目表中复制就绪作业,并将其粘贴到项目表中最后一个非空行中。但是,似乎不想从预测表中清除内容。而且我希望在清除Ready项目后立即上移所有项目的附加功能。

As is, the script will copy the "Ready" job from the forecasted projects sheet and paste it in the projects sheet in the last non empty row. However, it does not seem to want to clear the contents from the forecasted sheet. And I would like the added functionality of shifting up all the projects as soon as it clears the Ready one.

function onEdit(e) {     //Move forecasted project to Projects
  if (e.value === 'Ready') {
    var sheet = e.range.getSheet();
    if (sheet.getSheetName() == 'Projects Forecast') {    // Name of the sheet with the forecasted projects
      logSheet = e.source.getSheetByName('Projects');   // Name of the Projects sheet
      var row = e.range.getRow(); 
      var lastRow = logSheet.getLastRow();
      var range = sheet.getRange(row, 1, 1, sheet.getLastColumn()); 
      range.copyTo(logSheet.getRange(lastRow + 1, 1),{contentsOnly:true});
      sheet.clearContents(row);
    }
  }
}


推荐答案

要清除内容,请将sheet.clearContents(row)替换为

To clear the contents replace sheet.clearContents(row) with

range.clearContent();

但是我建议您仅通过将sheet.clearContents(row)替换为

However may I suggest that you simply delete the row by replacing sheet.clearContents(row) with

sheet.deleteRow(row);

然后,如果您确实想要相同数量的行,则可以插入一行

and then if you really want the same number of rows you can insert a row

sheet.insertRowsAfter(sheet.getMaxRows(), 1);

应保留工作表最后一行的格式。

which should retain the formatting of the very last row of the sheet.

这篇关于Google表格将行复制并粘贴到另一张表格中,然后从第一张表格中删除内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆