Renan Otero
Renan Otero

Reputation: 341

How load a specific sheet from a Spreadsheet

I have a Spreadsheet that contains a lot of sheets, and I need to load one of these sheets, how can I do that?

Here is a photo of the sheets in my Spreadsheet sheets

Here is my idea how to do it:

var sheet = SpreadsheetApp.openById(index).getSheetByName('Geração de Demanda');

Should that be working?

Upvotes: 16

Views: 46058

Answers (3)

Mariusz
Mariusz

Reputation: 9

Hope all is well at your end,

You can also create a drop down list with all sheets names and run below script to automatically go to designated sheet.

function goto () {

var ss = SpreadsheetApp.getActiveSpreadsheet();
var nameRange = ss.getActiveSheet().getRange(2, 2);//the drop down is in B2 cell
var nameValue = nameRange.getValue();

ss.setActiveSheet(ss.getSheetByName(nameValue));

}

Hope that will help too

Have a good one

Upvotes: 0

Jeyhun
Jeyhun

Reputation: 1

I know this is an old question. But still... var ss = SpreadsheetApp.getActiveSpreadsheet();

var sheet = ss.getSheets()[1];

I guess this is the most convenient way, as you dont have to deal with name, just indicate sheet number... [1] indicates second sheet... As you may guess numbering starts from 0 and on...

Upvotes: 0

Serge insas
Serge insas

Reputation: 46822

You're almost there... what you want is to make that sheet 'active' so try this :

var sheet = SpreadsheetApp.getActiveSpreadsheet();
SpreadsheetApp.setActiveSheet(sheet.getSheetByName('Geração de Demanda'))

Upvotes: 32

Related Questions