How to get sheet by name in Google Sheets

Using Apps Script, you can easily get sheet by name using this method in the Spreadsheet class:

getSheetByName(nameOfSheet);

Example of usage

In this example, there are 2 sheets named “Apple” and “Banana”.

This script should get the “Banana” sheet and print out all the values in it.

function GetBananaValues() {
  var sheet = SpreadsheetApp.getActive().getSheetByName("Banana");

  var rows = sheet.getLastRow();
  for (var i=1; i <= rows; i++)
  {
    console.log(sheet.getRange("A"+i).getValue())
  }
}

When you run it, you should get this:

get sheet by name in Google Sheets

If you want to get the values from “Apple” sheet, simply change to getSheetByName("Apple").