Reputation: 1
I have the following code:
var ee = SpreadsheetApp.getActiveSheet().getName();
if (ee == "Stuff") {
SpreadsheetApp.getActiveSheet().getRange('B2').setValue(emailAddress);
}
else {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Stuff").getRange('B2').setValue(emailAddress);
}
}
When my activesheet is "MAIN", the 'else' is executed and the value of 'emailaddress' goes into cell B2 on the "Stuff" sheet. BUT when my active sheet is "Stuff", even though the debugger shows that the first line is executed, NOTHING goes into B2!
Thanks.
Upvotes: 0
Views: 484
Reputation: 2822
Why not just always execute this?
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Stuff").getRange('B2').setValue(emailAddress);
You don't need the "if" because you do not have 2 different behaviors there. You're doing the same action in both parts. You're writing to the sheet called "Stuff".
Upvotes: 3