I am very new to scripts and am trying to insert each tab name into their own M1 cell which I would like to be triggered by onSelectionChange(e) as the tab names are constantly updating.
This is the only code I have found that seems to do what I need:
function changeName() {
var key = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange('M1').setValue(key);
}
function onSelectionChange(e) {
changeName()
}
The only thing is, I need it to exclude the tab 'Class List' but for the life of me cannot work how this can be done.
I would like to mention the following two points:
Take advantage of the event object which gives you information regarding the selection in the sheet.
to exclude a sheet you can add an if
condition and run the code inside of it only if the sheet name of the active sheet is different from Class List
.
function changeName(e) {
const as = e.source.getActiveSheet(); // active sheet
const nas = as.getName(); // name of the active sheet
if (nas !="Class List"){
as.getRange('M1').setValue(nas);
}
}
function onSelectionChange(e) {
changeName(e);
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments