I have a file that includes a variety of reference sheets and sheets that are only used at the end of the academic year plus a tab/sheet for individual students. Students come and go so I need the student tabs to be alphabetized. I've tried combining different pieces from various searches. The only thing that works for sure is hiding the ending tabs (last section below).
What I would like is the following:
- Tabs that stay in positions 1-4: "Active Special Programs", "Demographics","Master","Blank"
- Student Tabs next that are alphabetized by tab name
- Another list of tabs that will specifically need to stay at the end of the list and hidden (typically they stay hidden but sorting makes them viewable again)
2nd Attempt ***EDIT - I found the mistake and got this work. Just need to combine this with the ability to hide the ending tabs. ***
function sheetNames() { var ss = SpreadsheetApp.getActiveSpreadsheet(); // Store all the worksheets in this array var sheetNameArray = []; var sheets = ss.getSheets(); for (var i = 0; i < sheets.length; i++) { sheetNameArray.push(sheets[i].getName()); } sheetNameArray.sort(); // Reorder the sheets. for( var j = 0; j < sheets.length; j++ ) { ss.setActiveSheet(ss.getSheetByName(sheetNameArray[j])); ss.moveActiveSheet(j + 1); } ["Active Special Programs","Demographics","Master","Blank"].forEach((name,i)=>{ ss.setActiveSheet(ss.getSheetByName(name)); ss.moveActiveSheet(i + 1); }) // Define the names of the sheets you want to move to the end var sheetsToMove = ["Compliance Charts", "Course List", "Completions","Read Me!","Read Me!!!","Roster w/ Links","Summer Enrichment","Transcript Template Transfer","Course Numbers","Course Completion Response","Data Pull","Dates","Definitions","Exams"]; // Replace with your sheet names sheetsToMove.forEach(function(sheetName) { var sheet = ss.getSheetByName(sheetName); if (sheet) { // Move the sheet to the last position ss.setActiveSheet(sheet); ss.moveActiveSheet(ss.getSheets().length); } else { Logger.log("Sheet '" + sheetName + "' not found."); } }); } Hiding the ending tabs EDIT - This part works as expected, would like to combine it with the alpha/sort function
function organizeAndHideTabs() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheetsToMoveAndHide = ["Compliance Charts", "Course List", "Completions","Read Me!","Read Me!!!","Roster w/ Links","Summer Enrichment","Transcript Template Transfer","Course Numbers","Course Completion Response","Data Pull","Dates","Definitions","Exams"]; // Replace with your sheet names // Move the specified sheets to the end sheetsToMoveAndHide.forEach(sheetName => { const sheet = ss.getSheetByName(sheetName); if (sheet) { ss.setActiveSheet(sheet); // Activate the sheet to be moved ss.moveActiveSheet(ss.getSheets().length); // Move to the last position } }); // Hide the specified sheets sheetsToMoveAndHide.forEach(sheetName => { const sheet = ss.getSheetByName(sheetName); if (sheet && !sheet.isSheetHidden()) { // Check if not already hidden sheet.hideSheet(); } }); }