How to Reorder Worksheets in Google Spreadsheets by Name Using Apps Script
If you work with complex or large Google Spreadsheets, you’ve probably come across a situation where your worksheets (tabs at the bottom) are out of order. Maybe they were created at different times, or someone else added them in random order. Manually rearranging them can be tedious—especially if you have 20, 50, or even 100+ sheets.
The good news is: you can automatically reorder all worksheets alphabetically by name using Google Apps Script.
In this comprehensive guide, we’ll walk you through the what, why, and how of reordering Google Sheets tabs by name using a script. You’ll get full working code, a breakdown of how it works, and bonus tips to customize it further.
Here are some real-world reasons why people want their sheets sorted alphabetically:
Easier navigation when there are dozens of sheets
Consistent structure for shared documents
Useful in reporting dashboards, student or client lists
Automation of repetitive file maintenance
Clean organization for exported reports, logs, or imports
When you're dealing with a growing number of tabs, organizing them can drastically improve your productivity and data accessibility.
Yes, Google Sheets allows manual reordering by dragging tabs left or right. But this quickly becomes inefficient for large spreadsheets, especially when you're trying to maintain an alphabetical or numeric order.
That’s where Google Apps Script becomes a powerful ally.
To use Apps Script:
Open your Google Spreadsheet.
Click on Extensions > Apps Script.
A new tab opens with the script editor.
Delete any default code and paste in your custom script.
Click the disk icon to save and Run the script.
Now, let’s write the code to reorder your sheets alphabetically.
Get the Active Spreadsheet
SpreadsheetApp.getActiveSpreadsheet() fetches the current spreadsheet.
Fetch All Sheets
getSheets() returns an array of all worksheet tabs.
Map to Name-Sheet Pairs
We create an array of objects: { name: sheetName, sheet: sheetObject }
Sort Alphabetically
We sort the array using localeCompare() for proper alphabetical ordering (case-insensitive).
Reorder Sheets
Google Sheets allows repositioning using moveActiveSheet(index), which is 1-based (first position is 1).
Flush
SpreadsheetApp.flush() forces pending changes to be applied immediately.
The default code uses toLowerCase() to make the sorting case-insensitive. If you want case-sensitive sorting (so uppercase tabs come before lowercase), remove the toLowerCase():
If you prefer descending order (Z to A), modify the sort like this:
Suppose you want to exclude specific sheets like "Dashboard", "Summary", or "Settings". You can do this by filtering them out:
Then sort and move just those sheets. This keeps important tabs like dashboards fixed at the front.
You can automate this task to run daily or weekly.
In the script editor, click on the clock icon in the toolbar.
Click Add Trigger.
Choose the reorderSheetsAlphabetically function.
Set the event to Time-driven, and select a frequency.
Your sheets will now stay sorted on autopilot.
Teachers: Reorder student sheets alphabetically.
Project Managers: Organize task sheets by team or department name.
Business Analysts: Keep monthly or regional data in order.
Data Entry Teams: Automatically sort new tabs created via form submissions.
The script requires edit access to the spreadsheet.
moveActiveSheet(index) reorders based on a 1-based index, so calculations must account for this.
Sheet names must be unique.
Sheets shared with other users may briefly re-render during execution.
Reordering worksheets alphabetically in Google Sheets can drastically improve usability and organization—especially for spreadsheets with many tabs. While manual reordering works for a few tabs, Google Apps Script provides a much more scalable and automated solution.
With just a few lines of code, you can sort your entire spreadsheet's tabs in seconds—and even automate the task going forward.
So next time your spreadsheet feels chaotic, let the script do the organizing. Clean, structured data starts with clean, structured sheets.