When you have errors with working with sheet objects like here you can easily identify the source by the kind of missing value it’s pulling from.
undefined
is undefined, meaning the variable for the sheet was never given a value or has been set to undefined.
the variable is set to null
when you are trying to get a tab by a name that doesn’t exist, as is the case here.
Anything else probably means you are accessing the wrong variable.