To whom it may concern,
I am running into issues where I have multiple sheets in a workbook. Two of which are:
"Stage Crew" and
"Stage Crew Points"
I am trying to sort BOTH in my script after adding a row to each.
The sort seems to be messing up my data on "Stage Crew Points".
I suspect the selection of the sheet PRIOR to sorting may be related.
Could someone look at my code and give me some suggestions?
This is AFTER the new row is added to the 2 sheets separately.
Those parts of the code seem to be working well.
It is just on the sort, that it gets goofed up.
/***********************************************/
// Stage Crew
// Sort Ascending by Last Name, then First Name
/***********************************************/
// Column A = Last Name // Column B = First Name
ss.setActiveSheet(ss.getSheetByName('Stage Crew'), true);
var sheet = ss.getActiveSheet();
var lastrow = ss.getLastRow();
var lastcol = ss.getLastColumn();
// Try combining the sort with the Activate...
sheet.getRange(2, 1, lastrow -1, lastcol).activate().sort([{column: 1, ascending: true}, {column: 2, ascending: true}]);
// Select A1, so not all highlighted
sheet.getRange(1, 1).activate();
/***********************************************/
// Stage Crew Points
// Sort Ascending by Last Name, then First Name
/***********************************************/
/* 1/26/21 - For some reason the SORT is still not working right.
Seems to be sorting only the col A - L, not M - END
*/
// Column A = Last Name // Column B = First Name
ss.setActiveSheet(ss.getSheetByName('Stage Crew Points'), true);
var sheet = ss.getActiveSheet();
var lastrow = getBORDERRowByColumnArray(sheet_PointsList);
var lastcol = sheet.getLastColumn();
/* JS 1/26/21 Above */
// Try combining the sort with the Activate...
sheet.getRange(2, 1, lastrow -2 , lastcol).activate().sort([{column: 1, ascending: true}, {column: 2, ascending: true}]);
// Select A1, so not all highlighted
sheet.getRange(1, 1).activate();
Any suggestions are appreciated.
question from:
https://stackoverflow.com/questions/65909575/google-script-sheets-sorting-multiple-sheets-not-working-right 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…