Created
June 9, 2016 17:41
-
-
Save bpmore/0337b4ac1fc9110975e70fc5df53203f to your computer and use it in GitHub Desktop.
Sort Tabs in Google Spreadsheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Copy/Paste the information below to the clipboard | |
2. Open the spreadsheet whose sheets need to be alphabetised | |
3. Choose Tools > Script editor > Blank (this opens a new tab in the browser) | |
4. Press Control+A followed by Control+V copy and paste the script in | |
5. Press Control+S to save the script | |
6. Choose Run > sortSheets | |
7. Go back to the spreadsheet tab to view the new sorted tab order | |
--Copy everything below this line-- | |
function sortSheets () { | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheetNameArray = []; | |
var sheets = ss.getSheets(); | |
for (var i = 0; i < sheets.length; i++) { | |
sheetNameArray.push(sheets[i].getName()); | |
} | |
sheetNameArray.sort(); | |
for( var j = 0; j < sheets.length; j++ ) { | |
ss.setActiveSheet(ss.getSheetByName(sheetNameArray[j])); | |
ss.moveActiveSheet(j + 1); | |
} | |
} |
Thank you!
anyway to sort them in descending alphabetical order?
Thank you!Yes, should work with reverse().
sheetNameArray.sort().reverse();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I also am looking for a unique solution. Your alphabetizer works like a dream for me and i thought i could figure out my own solution but every example of other examples were varied in their style. I understood all of them separately, but when i tried to combine them... the downward spiral.
I currently have about 60 sheets that I'm trying to organize by:
I had the first 5 sheets and two color groups working fine but i did something somewhere trying to wrap it up and destroyed al the progress i made. The more i tried to cobble it back together the worse it got until i finally realized i had spent hours just staring at the screen. I'm one of those stubborn people and I love to figure things out, but right now I'm that guy with just enough knowledge to be dangerous. I patiently await my opportunity to be guided to enlightenment.