Skip to content

Instantly share code, notes, and snippets.

@yradunchev
Forked from bpmore/sort-tabs.txt
Created May 24, 2020 12:30
Show Gist options
  • Save yradunchev/41c888db7bcbb355904391f9c1e19370 to your computer and use it in GitHub Desktop.
Save yradunchev/41c888db7bcbb355904391f9c1e19370 to your computer and use it in GitHub Desktop.
Sort Tabs in Google Spreadsheets
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment