0
votes

I have a script that at one point worked great. I added columns, the script stopped working. I finally realized that when I remove these columns it started working again. It appears to only be a problem on the Listing stats tab. However the C2C script does not work when the Listing Stats code is in place- I am guessing since the Listing Stats script is listed first.

(The script is two part. I need to sort two different tabs differently.)

Any thoughts as to why it would stop working with those extra columns added? New to scripts, please talk slowly ;)

DOC HERE (I believe I have set the settings correctly for anyone to see.) https://docs.google.com/spreadsheets/d/175wBQpoGjRkUOIHjI9e056zhQHOwdexPqGNSEaat-cc/edit#gid=499403712

SCRIPT BELOW

function onEdit(){
// -- Listing Stats Tab, sorts by Status (3) then Go Live (15) starting at line 8
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("LISTING STATS");
  var lr = ss.getLastRow();
  var lc = ss.getLastColumn();
  var range = ss.getRange(9, 1, lr - 1, lc)
  range.sort([{column: 2},{column: 15}]);

  // -- C2C Tab, sorts by Status (2) then Closing (8) starting at line 13
  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("C2C");
  var lr = ss.getLastRow();
  var lc = ss.getLastColumn();
  var range = ss.getRange(14, 1, lr - 1, lc)
  range.sort([{column: 2},{column: 8}]);


}
1
This is the error that I get when I press play in the script editor. "The coordinates of the range are outside the dimensions of the sheet. (line 11, file "Code")Dismiss" - Salea
This is the error that I get when I press play in the script editor. "The coordinates of the range are outside the dimensions of the sheet. (line 11, file "Code")Dismiss" I have done little to debug because I do not know where to even start. When I remove the Listing Stats section, it works on the C2C. When Listing Stats is in place neither works. When I remove 20+ columns from Listing Stats it works correctly. Thanks for your help. - Salea
the second: var lr = ss.getLastRow(); - Salea

1 Answers

-1
votes

I think the error arises because you are trying to execute 2 getActiveSpreadsheet().getSheetByName() at the same time. You can't have 2 active sheets at the same time because only one can be active at a time.

Work on one of the sheets first, then activate the second using setActiveSheet(sheet, restoreSelection).