I am interested in writing a function that would sort some rows with respect to values in a named column. For example, suppose I have named the range A3:C8 as Data, and column A (i.e. A:A) as Surname, and I want to order it with respect to surname. Something like the following code does this
function sortBySurname() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var range = ss.getRangeByName("Data");
range.sort(1);
}
However, I would like to achieve the same without explicitly using the fact that column Surname is the first one, i.e. what's the right way to write
range.sort("Surname") instead of range.sort(1)?