How To Get A List Of Sheet Names In Google Sheets With Script?

Posted by Sean's Blog on Friday, January 28, 2022

There’s no built-in formula to do this, and we have to write our own script with Google’s Apps Script to achieve the function.

  1. First, go to the Extensions → Apps Script.

  2. Second, write our own method getSheetsName in the Apps Script console, and save.

Code snippets:

function getSheetsName() {
var sheetNames = new Array()
var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i=0 ; i<sheets.length ; i++) {
sheetNames.push( [ sheets[i].getName() ] )
}
return sheetNames
}

Then go back to your sheet, and type the formula with the function name we just created in the Apps Script.

Finally, you can see the result shown below. 🎉


comments powered by Disqus