1

I have a simple script that I am trying to make to sort a specific column, but for some reason the code I've taken directly from the examples online (from the API) is causing an error message:

Cell reference out of range (line 7, file "Code")

My code is as follows:

function Remove_Duplicates() {
  var ss = SpreadsheetApp.getActiveSheet();
  var row = 2;
  var col = 7;
  cellStr = ss.getRange(row,col).getValue();
  Logger.log(cellStr);
  ss.getRange("G2:H100").sort([{column: 1, ascending: true}]);


}
  • @Rubén it is bound to a sheet, and the error is: "cell reference out of range" – 1QuickQuestion Oct 22 '17 at 2:43
  • @Rubén sorry about that: Cell reference out of range (line 7, file "Code") – 1QuickQuestion Oct 22 '17 at 3:32
2

According to the example for sort(sortSpecObj), Column A has column number 1, Column B has column number 2, and so on.

The error occurs because the range to be sorted is G2:H100 but column A (column 1) isn't included.

  • 1
    Wow, thanks! I have no idea how I missed that; I assumed it was a reference to the range entered not necessarily the entire sheet. Thanks alot. – 1QuickQuestion Oct 22 '17 at 3:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.