Last active
July 10, 2018 17:58
-
-
Save john-hix/3380512423d90bdd47aa43311b3586d9 to your computer and use it in GitHub Desktop.
Google Sheets "sheetExists" function (detect if sheet exists)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sheetExists(sheetName) { | |
if (typeof sheetName !== "string") { | |
throw ("The sheetExists function requires string input.") | |
} | |
var allSheets = SpreadsheetApp.getActive().getSheets(); | |
var foundSheet = false; | |
var len = allSheets.length; | |
var chkThisIndex = 0; | |
while (!foundSheet && chkThisIndex < len) { | |
if (allSheets[chkThisIndex].getName() === sheetName) { | |
foundSheet = true; | |
} else { | |
chkThisIndex++ | |
} | |
} | |
return foundSheet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment