Skip to content

Instantly share code, notes, and snippets.

@ndthanh
Created December 10, 2018 17:33
Show Gist options
  • Save ndthanh/af06e4256859da8d66312905340f9d11 to your computer and use it in GitHub Desktop.
Save ndthanh/af06e4256859da8d66312905340f9d11 to your computer and use it in GitHub Desktop.
//3. sort sheets alphabetically
function sortSheets() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheets = spreadsheet.getSheets();
var sheetNames = [];
sheets.forEach(function(sheet,i) {
sheetNames.push(sheet.getName());
});
sheetNames.sort().forEach(function(sheet,i) {
spreadsheet.getSheetByName(sheet).activate();
spreadsheet.moveActiveSheet(i + 1);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment