Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

Google Script - Sheets - Sorting Multiple Sheets - Not working right

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...