Reputation: 1
I have the simple trigger set to onEdit and used the code below to execute it. Everything works fine but when I try to shift the tab where my main function executes, the whole trigger stopped working and typeError comes up "cannot read property 'range' of undefined"
I have 3 sheets. Main sheet where function runs, 2nd sheet where my onEdit takes place and a secondary sheet. Trigger won't work when I shift my main sheet to the second or last tab.
function onEdit(e) {
if (e.range.getA1Notation() == 'C9') {
if (/^\w+$/.test(e.value)) {
this[e.value]();
e.range.clear();
}
}
}
Upvotes: 0
Views: 59
Reputation: 1
I've found out why. The issue lies in my main function code on how I open another sheet. When my main sheet is in the first tab, I can get it by openbyURL. This won't work when I shift the tab away.
var mainSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Name');
I replaced the openbyurl with the liner above and everything works
Upvotes: 0
Reputation: 1
You can't run onEdit as it will return that error. Your onEdit should work even you shift the tab, just try it on your sheet.
Upvotes: 0