当前位置:首页 > 未分类 > 正文内容

Reorder Worksheets in Google Spreadsheets by Name

ceacer3周前 (05-02)未分类8495

You have a Google Spreadsheet with multiple worksheets and, to making organization easier, you would like to reorder or sort the various sheets inside the spreadsheet by name.

Google Apps Script to the rescue. Paste the snippet inside the Google Sheet’s script editor and run the sortGoogleSheets method from the menu.

/* Credit: https://gist.github.com/chipoglesby/26fa70a35f0b420ffc23 */

function sortGoogleSheets() {
  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);
  }
}

相关文章

How to Create Multiple Sub

How to Create Multiple Sub

A teacher would like to create separate Google Drive folders for each student in her class. Within e...

How to Sort Google Sheets Automatically with Apps Script

How to Sort Google Sheets Automatically with Apps Script

This Google Spreadsheet on Udemy courses has about 50 sheets, one for each programming language, and...

How to Make Phone Numbers Callable in Google Sheets and Docs

How to Make Phone Numbers Callable in Google Sheets and Docs

This tutorial explains how to make phone numbers clickable within Google Sheets, Slides and Google D...

How to Make Personalized Place Cards with Guest Names

How to Make Personalized Place Cards with Guest Names

Whether it is a wedding party or a business conference, those tent-shaped place cards are ideal for...

Color Codes for Google Spreadsheets

This Google Script converts the currently active Google Spreadsheet into a square grid of randomly c...

How to Insert Images in Google Sheet Cells

How to Insert Images in Google Sheet Cells

This tutorial explores the different options for inserting images in Google Sheets. We’ll also discu...