LoginSignup
2
1

More than 1 year has passed since last update.

Google Apps Script でスプレッドシートの最終行に値をコピーする話

Posted at

はじめに

Google Apps Script (GAS) の copyTo() 関数を使ってスプレッドシートのセルをコピー&ペーストします。

Apps Script リファレンス

copyTo(destination)

サンプルコード

function onCopy() {
  const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  const source = spreadsheet.getSheetByName("<コピー元のシート名>").getRange("<セルの範囲>");
  const row = source.getLastRow();
  const column = source.getLastColumn();

  // コピー
  const sheet = spreadsheet.getSheetByName("<コピー先のシート名>");
  const insert = sheet.getLastRow() + 1;
  const destination = sheet.getRange(insert, 1, row, column);
  source.copyTo(destination);
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1