复制并粘贴到下一列+最后一行(GOOGLE SCRIPT) [英] Copy and Paste to the next Column + Last Row (GOOGLE SCRIPT)

查看:98
本文介绍了复制并粘贴到下一列+最后一行(GOOGLE SCRIPT)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想复制并粘贴到下一列+最后一行.我在下面尝试,但没有用,请查看示例图片

  function CopyPasteFrTo(){var ss = SpreadsheetApp.getActive();var shfr = ss.getSheetByName('From');var shto = ss.getSheetByName('To');shfr.getRange('A1:N').copyTo(shto.getRange("A1"),SpreadsheetApp.CopyPasteType.PASTE_NORMAL,false);shfr.getRange('A2:F').copyTo(shto.getRange(shto.getLastRow()+ 1,1),SpreadsheetApp.CopyPasteType.PASTE_NORMAL,false);shfr.getRange('K2:N').copyTo(shto.getRange(shfr.getLastColumn()+ 1,7),SpreadsheetApp.CopyPasteType.PASTE_NORMAL,false);shfr.getRange('G2:J').copyTo(shto.getRange(shfr.getLastColumn()+ 1,11),SpreadsheetApp.CopyPasteType.PASTE_NORMAL,false);}; 

I would like to copy and paste to the next column + last row. I try below but doesn't work and please see sample picture

function CopyPasteFrTo() {
  var ss=SpreadsheetApp.getActive();
  var shfr=ss.getSheetByName('From');
  var shto=ss.getSheetByName('To');
  shfr.getRange('A1:N').copyTo(shto.getRange("A1"), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  shfr.getRange('A2:F').copyTo(shto.getRange(shto.getLastRow()+1,1), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  shfr.getRange('K2:N').copyTo(shto.getRange(shfr.getLastColumn()+1,7), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
  shfr.getRange('G2:J').copyTo(shto.getRange(shfr.getLastColumn()+1,11), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
};

see sample here

解决方案

I believe your goal as follows.

  • When I saw your sample image, it seems that you want to copy the values in the same sheet. But when I saw your script, you want to copy the values from "From" to "To" sheet. From this situation, I would like to believe your goal as your sample image.
  • In your sample image, for the same sheet,
    • You want to copy the cells "A2:F" (last row of the data range.) to the column "A" of the next row of the last row.

    • You want to copy the cells "K2:N" (last row of the data range.) to the column "G" of the next row of the last row.

    • You want to copy the cells "G2:J" (last row of the data range.) to the column "K" of the next row of the last row.

    • Your sample image is as follows (This is from your question.).

Sample script:

function myFunction() {
  const sheetName = "Sheet1";  // Please set the sheetname.

  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  const lastRow = sheet.getLastRow();
  sheet.getRange("A2:F" + lastRow).copyTo(sheet.getRange("A" + (lastRow + 1)));
  sheet.getRange("K2:N" + lastRow).copyTo(sheet.getRange("G" + (lastRow + 1)));
  sheet.getRange("G2:J" + lastRow).copyTo(sheet.getRange("K" + (lastRow + 1)));
}

Reference:

这篇关于复制并粘贴到下一列+最后一行(GOOGLE SCRIPT)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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