以下代码用于根据源行的第7列中的条件将行从一张纸移动到另一张纸上。
现在我收到错误消息,“目标范围的坐标超出了图纸的尺寸。”
非常感谢您的帮助!
谢谢!
function moveDispos() {
Logger.clear();
var ss = SpreadsheetApp.openById("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
var sheet = ss.getSheetByName("XXXXXXX");
var startRow = 2;
var lastRow = sheet.getLastRow();
var ColToWatch = 7;
var moves = [];
var data = sheet.getDataRange().getValues();
for (var i = startRow - 1; i <= lastRow - 1; i++) {
var rowVal = data[i][6];
if (rowVal === "XXXXX") {
moves.push(Number(i + 1));
}
}
var moveFrom = "XXXXXXX";
var moveTo = "XXXX XXXXXX";
var sourceSheet = ss.getSheetByName(moveFrom);
var targetSheet = ss.getSheetByName(moveTo);
for (var i = 0; i < moves.length; i++) {
move(moves[i] - i, sourceSheet, targetSheet);
}
}
function move(sourceRow, sourceSheet, targetSheet) {
var sourceRange = sourceSheet.getRange(sourceRow, 1, 1, sourceSheet.getLastColumn());
var targetRange = targetSheet.getRange(targetSheet.getDataRange().getLastRow() + 1, 1);
sourceRange.copyTo(targetRange);
sourceSheet.deleteRow(sourceRow);
}