Enhance Productivity with Google Apps Script: Instantly Rearrange Google Sheets Tabs Right to Left

Recommended for:

For those considering improving googlesheets efficiency.

Those with many sheet tabs in one file.

Google Sheets is a very convenient tool, but a troublesome aspect is moving sheet tabs.

When there are many tabs, the basic method of moving them one by one can be time-consuming, especially when you want to move a tab from the far right to the far left. In such cases, you can use Google Apps Script to move them all at once.

If you need to repeatedly move sheet tabs to the far left, using Google Apps Script can make the process easier.

TOC

The script to move the selected sheet tab to the far left

// Move the selected sheet tab to the far left
function moveActiveSheetToLeft() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = spreadsheet.getActiveSheet();
  spreadsheet.moveActiveSheet(1);
}

Here is the script to move the selected sheet tab to the far left.

You can easily copy the script by clicking the copy icon in the top right corner of the code block.

You can copy and use the script as it is.

The number in the fourth line of ‘moveActiveSheet(1)’ determines to which position the sheet will be moved. For example, if you want to move the sheet to the third position, change it to (3).

Script to move the selected sheet tab to the far right

// Move the selected sheet tab to the far right
function moveActiveSheetToRight() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var totalSheets = spreadsheet.getNumSheets();
  var activeSheet = spreadsheet.getActiveSheet();
  spreadsheet.moveActiveSheet(totalSheets);
}

Here’s the script for moving the selected sheet to the far right, opposite to what we did earlier.

You can copy and use it as is.

How to Use the Script

スクリプトの使用方法
  1. Toolbar – Extensions – Apps Script
  2. Paste the script
  3. Save the script
  4. Run
  5. The selected sheet tab moves to the left (right).
STEP
Select ‘Extensions – Apps Script’ from the toolbar.

Open the spreadsheet, then click on “Extensions” in the toolbar and select “Apps Script.”

STEP
Paste the script.

Since `function myFunction(){}` is already there at the beginning, delete it and paste the above script.

STEP
Press “Save Project”
STEP
Press “Run.”

If you’re running the script for the first time, you need to authorize it.

Therefore, press “Review Permissions.

Next, press “Advanced.”

Press “Go to Untitled project (Unsafe).”

After that, press “Allow.”

STEP
When executed, the selected sheet tab moves to the far left.

In the image above, “Sheet 5” has moved to the far left.

If there are only a few sheets, you can move them easily without using Apps Script, but when there are many, using Apps Script can save you time.

Basic Method for Moving Sheet Tabs (Without Using Google Apps Script)

Drag & Drop
Right-click Menu

Drag & Drop
  1. Hover the cursor over the sheet tab you want to move.
  2. Click and hold the sheet tab with the mouse.
  3. Drag the sheet tab all the way to the left.
  4. Release the sheet tab.
Right-click Menu
  1. Right-click on the sheet tab you want to move.
  2. Select “Move left” from the menu that appears.

When there are only a few sheet tabs, using drag and drop is an easy way to move them.

Summary

  • When there are many sheet tabs, it’s easier to use Google Apps Script to move them to the far left.
  • If there are only a few sheet tabs, it’s quicker to move them with drag and drop.

Move the sheet tab to the far left.

// Move the selected sheet tab to the far left
function moveActiveSheetToLeft() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var activeSheet = spreadsheet.getActiveSheet();
  spreadsheet.moveActiveSheet(1);
}

シートタブを右端に移動させる

// Move the selected sheet tab to the far right
function moveActiveSheetToRight() {
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var totalSheets = spreadsheet.getNumSheets();
  var activeSheet = spreadsheet.getActiveSheet();
  spreadsheet.moveActiveSheet(totalSheets);
}

Please use this function when you have many sheet tabs.

Our company offers support for improving work efficiency through the use of Google Apps Script.
If you need assistance with Google Apps Script customization or error resolution, please feel free to contact us.
We are fully committed to supporting your business improvements.

Contact us here

Let's share this post !

Comments

To comment

TOC