The coordinates of the target range are outside the dimensions of the sheet

邮差的信 提交于 2020-03-04 20:51:33

问题


I use this code and while in the past it worked well, today I received this error message:

The coordinates of the target range are outside the dimensions of the sheet. (line 27, ___.gs)

My code is not too complex:

function onEdit() {
  var sheetNameToWatch1 = "Assign_Page";
  var columnNumberToWatch = 19;
  var valueToWatch = "Delivred";
  var sheetNameToMoveTheRowTo = "K_Delivery_Archive";
  var sheetNameToMoveTheRowTo2 = "Buffering";

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getActiveCell();

  if (sheet.getName() == sheetNameToWatch1 && range.getColumn() == columnNumberToWatch && range.getValue() == valueToWatch) {
    var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
    var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    sheet.getRange(range.getRow(), 1, 1, 22).copyTo(targetRange, {contentsOnly: true});

    var targetSheet2 = ss.getSheetByName(sheetNameToMoveTheRowTo2); 
    var targetRange2 = targetSheet2.getRange(targetSheet2.getLastRow() + 1, 1);
    sheet.getRange(range.getRow(), 1, 1, 22).copyTo(targetRange2, {contentsOnly: true});

    sheet.deleteRow(range.getRow()); // line 27

    var Sheet1 = ss.getSheetByName("Clients_Page");
    var Sheet2 = ss.getSheetByName("Assign_Page");
    var Sheet3 = ss.getSheetByName("Report");
    var Sheet4 = ss.getSheetByName("Delivery_Information");
    Sheet4.showSheet();
    Sheet1.hideSheet();
    Sheet2.hideSheet();
    Sheet3.hideSheet();
  }
}

What causes this error, and how can I resolve it?


回答1:


It's very likely that the problem is due to

targetSheet2.getLastRow()+ 1

The proper solution will depend on several factors that are not mentioned by the OP, but here is a hint:

If the sheet has open ended formulas that return "" then the last row is the same as the maximum number of rows in the sheet and inserting more rows will not solve the problem.



来源:https://stackoverflow.com/questions/46825809/the-coordinates-of-the-target-range-are-outside-the-dimensions-of-the-sheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!