*TL:DR I would like to sort an entire sheet automatically with the following conditions.
- Sort entire sheet by columns 1 2 and 3
- Move any rows with "Z Shipped" in column 1 to the bottom of the populated list (there are many rows with blank data in column 1, so I want "other data, Z Shipped data, blank rows".*
Hi there, I as the title states, I am trying to sort my google sheet through multiple ranges. I have pasted my current code below that I have found gets me close, however I keep getting a
"The coordinates of the range are outside the dimensions of the sheet."
error on the second "newRange.sort(newSortOrder)" line.
I am not sure if my current code is what I need to have or not. I have no expertise in this and just try to find functions that work online and am getting stuck on this one as it does not seem to be a common request.
function autosort() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var sortRange = "A3:E";
var range = ss.getRange(sortRange);
var sortOrder = [
{column: 1, ascending: true},
{column: 2, ascending: true},
{column: 3, ascending: true}
];
range.sort(sortOrder);
var status = ss.getDataRange().getLastRow();
for (var i=status;i>=1;i--){
if(ss.getRange(i,1).getValue()!=='Z Shipped') {break;}
}
var newSortRow = i+1;
var newSortRange = "A3:E"+newSortRow;
var newRange = ss.getRange(newSortRange);
var newSortOrder = [
{column: 2, ascending: true},
{column: 3, ascending: true}
];
newRange.sort(newSortOrder);
}