1

Writing a script to sort a sheet by a range , A4 to the bottom right cell (because rows and/or columns may be added). The script finds the cell of the last column/last row and then uses that in the range var. Problem is when I try to run this script it gives me "Missing ) after argument list. (line 8, file "Sort By Gamer Tag")". But I've closed all the "(".

Any advice?

Thanks

function sortByGamerTag() {

  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var sht=ss.getSheetByName('Master Summary 2');
  var lastRow=sht.getLastRow();
  var lastCol=sht.getLastColumn();
  var lastCell=sht.getCell(lastCol,lastRow);
  var range = sht.getRange("A4":lastCell);
  range.sort(2);

}



1 Answer 1

1

I think that there are 2 modification points in your script. Please confirm below.

Modification points :

  1. range of getRange(range) can be given by strings.
    • So please change from "A4":lastCell to "A4:" + lastCell.
  2. getCell() returns a given cell within a range. (Ref.) In your script, an error occurs at var lastCell=sht.getCell(lastCol,lastRow);.
    • So please change from var lastCell=sht.getCell(lastCol,lastRow); to var lastCell = sht.getRange(lastRow, lastCol).getA1Notation();.

Modified script :

Your script can be written by modifying above points as follows.

function sortByGamerTag() {
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var sht=ss.getSheetByName('Master Summary 2');
  var lastRow=sht.getLastRow();
  var lastCol=sht.getLastColumn();
  var lastCell = sht.getRange(lastRow, lastCol).getA1Notation();
  var range = sht.getRange("A4:" + lastCell);
  range.sort(2);
}

If I misunderstand your question, I'm sorry.

Sign up to request clarification or add additional context in comments.

2 Comments

no you understood perfectly. Thank you for explaining. I had not thought at all about the A1 Notation. Thank you.
Welcome. Thank you, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.