Reputation: 901
Did a search on this site for "INSERT_ROW getActiveSheet" and found one hit: Google Script: How can I run a script only when someone adds new rows. The accepted answer shows this code:
function myFunction(e){
Logger.log(e.changeType);
if(e.changeType=='INSERT_ROW'){
// do Something
Browser.msgBox('New row(s) added');
}
}
which is fine. The problem I am having is in the "// do something" part of the code, what I want to do is get the Active Sheet and ultimately the Active Range so that I can add formulas to the new rows programmatically when a user inserts new rows. I have tried both:
e.source.getActiveSheet().getName()
and
SpreadsheetApp.getActiveSheet().getName()
to attempt to get the name of the Active Sheet, but it keeps returning the first sheet in the spreadsheet and the range A1.
When I run this code:
Browser.msgBox(Utilities.jsonStringify(e));
it does not return the active sheet, only the authMode, changeType and user properties, as it shows it should in the documentation.
There must be a way, however, to find out what has been changed, otherwise what is the point of an onChange event?
Upvotes: 0
Views: 1886