I would like to retrieve data from a specific sheet in my document, but I don't want to use the name of the sheet as reference, but its position.

Google help says this:



Where Sheet1 is the name of the sheet.

Is there a way to use the sheet position instead?



1 Answer 1


Short answer

Use the getSheets() method from the Spreadsheet object of Google Apps Script


Google Sheets doesn't have a built-in function to get the sheet name by its position but it's possible to extended it by using Google Apps Script. The following is an example of a custom function that returns the sheet name given a valid position, otherwise return a custom error message.

function getSheetNameByPosition(position){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  // var sheets = ss.getSheets();
  var result = '';
  try {
    return ss.getSheets()[position-1].getName();
  } catch(e) {
    throw new Error('The position value is not valid');


Extending Google Sheets

  • I commented a line of the code as it's not necessary (you could remove it). This will improve performance. Oct 10, 2016 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.