Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move Sheet Tab to the Far Left Using Script

Is it possible to have a small script that will re-arrange the order of the sheet tabs moving the currently selected sheet tab to the far left (the beginning) of all the tabs in a Google Spreadsheet?

like image 269
PY_ Avatar asked Aug 17 '12 18:08

PY_


People also ask

How do I move a tab to the end in Google Sheets?

To move a sheet: Click and drag the tab of the sheet you want to move. Release the mouse to place the tab at the desired location.

How to easily rearrange sheets in Google Sheets?

You can click and drag any sheet left or right to change where it appears in relation to other sheets within your spreadsheet document. Left-click on and sheet and hold the mouse button while you drag the sheet either left or right. Release the mouse button to place the sheet in the new location.

What is getActiveSheet?

getActiveSheet() Gets the active sheet in a spreadsheet. The active sheet in a spreadsheet is the sheet that is being displayed in the spreadsheet UI.

How to arrange Google Sheets tabs in alphabetical order?

In a Google Sheet on the web, select a cell in a column, then choose Data | Sort Sheet By… options to sort either A-Z or Z-A.


2 Answers

Yes and No. It can be done by sweet name, but not by the current sheet you are looking at. Below is some code I wrote that moves a sweet to the first position every day.

function tab() { 

  var reportDate = new Date();
  var tabName = Utilities.formatDate(reportDate, 'MST', 'yyyy-MM-dd').toString(); 
  var tab = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabName);
  SpreadsheetApp.setActiveSheet(tab);
  SpreadsheetApp.getActiveSpreadsheet().moveActiveSheet(1);

} 
like image 64
Rommel Avatar answered Oct 13 '22 02:10

Rommel


function BacktotheFront() {
   SpreadsheetApp.getActiveSpreadsheet().moveActiveSheet(1);
}
like image 36
PY_ Avatar answered Oct 13 '22 02:10

PY_