ソース範囲で getValues() を使用し、宛先で setValues() を使用します。範囲が同じディメンションであることを確認する必要があります。その後、ソースを clear() できます。
これは、仕事をするユーティリティ関数です。gist としても利用できます。範囲オブジェクトをパラメーターとして受け取ることに注意してください。
コード
/**
* Move all values from source range to destination range. Upon
* completion, source range will be cleared. Source values will
* be moved into a destination range starting at the "top left"
* of the destination range, using the dimensions of the source
* range. This is a blind copy, with no overwrite test.
*
* @param {Range} source Range Object to take values from.
* @param {Range} destination Range Object to receive values.
*
* @returns nothing
*/
function moveRange(source,destination) {
var sourceSheet = source.getSheet();
var destSheet = destination.getSheet();
var sourceData = source.getValues();
var dest = destSheet.getRange(
destination.getRow(), // Top row of destination
destination.getColumn(), // left col of destination
sourceData.length, // # rows in source
sourceData[0].length); // # cols in source (elements in first row)
dest.setValues(sourceData);
source.clear();
}
テスト機能
テストが成功すると、ソース範囲全体がクリアされ、その内容が宛先範囲に値としてのみ表示されます。移動先として指定されているものに関係なく、移動先の寸法は移動元の寸法と一致します。移動を固定するのは左上隅のみです。
function test_moveRange() {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var destSheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];
var source = sourceSheet.getRange("A7:C10");
var destination = destSheet.getRange("C4:H2");
moveRange(source,destination);
}