Can the getRange
be used to have a named range instead of an area?
When I seem to do it, it says the argument must be a range.
For example,
Instead of:
getRange("A4:E7");
The area of A4:E7
has been made into a named range called 'Names' in sheet1.
Could you perhaps use:
var tableRange = SpreadsheetApp.getActiveSpreadsheet();.getRangeByName("Names");
getRange(tableRange);
Or is there any other way of doing it. The full code is:
function onEdit(event){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var editedCell = ss.getActiveCell();
var columnToSortBy = 1;
var tableRange = ss.getRangeByName("Names");
if(editedCell.getColumn() == columnToSortBy){
var range = ss.getRange(tableRange);
range.sort( { column : columnToSortBy } );
}
}
getActiveCell()
. The edit event passes the edited range to the script so you can just useevent.range.getColumn()
. – Hussite