Google Sheets: Exclude a Tab when Running a Script

B Library

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.

Marios

Explanation:

I would like to mention the following two points:

  1. Take advantage of the event object which gives you information regarding the selection in the sheet.

  2. 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.

Solution:

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Google App Script for Sheets - forEach works when running from editor but no data when running from time trigger

From Dev

Isolate script to one tab in Google Sheets

From Dev

Creating a Log tab of sent data using Google Sheets Apps Script

From Dev

Script to download several columns of a Google Sheets Tab into separate text files

From Dev

Capture data into a new tab before script clears columns (Google Sheets)

From Dev

Google sheets script to sort rows imported from another tab by column

From Dev

Problems with google sheets auto hide rows script running over and over

From Dev

Running multiple sheets under one google script, syntax error

From Dev

pre-loading custom functions when running sheets daily script

From Dev

Copy and Paste google sheets to another google sheets when specific tab is edited

From Dev

Google Sheets Completely exclude duplicates

From Dev

Exclude sheets when looping through sheets

From Dev

Error in Google App Script when submitting form data to Google Sheets

From Dev

setName when exporting a PDF from Google Sheets with Google Apps Script

From Dev

Keeping script running when tab is not the focus. (JS)

From Dev

How to commit changes made in active cell before running script? (Google Sheets / Google Apps Script)

From Dev

google script to keep a running total when updated

From Dev

Trying to fetch data from Google Sheets using Google script and displaying on web page having horizontal tab

From Dev

How do I exclude certain sheets/tabs from google app script?

From Dev

onChange specify tab google sheets

From Dev

Linking to another tab in Google Sheets

From Dev

Dynamic Tab linking in Google Sheets

From Dev

Google Sheets Custom Script

From Dev

Sharing Google Sheets with script

From Dev

Google Sheets Script getLastRow

From Dev

Google Sheets Script - Checkbox

From Dev

Finetune google sheets script

From Dev

Google Sheets Script Approval

From Dev

Google Sheets - Script to “Replace” instead of “Create”, when file name is the same

Related Related

  1. 1

    Google App Script for Sheets - forEach works when running from editor but no data when running from time trigger

  2. 2

    Isolate script to one tab in Google Sheets

  3. 3

    Creating a Log tab of sent data using Google Sheets Apps Script

  4. 4

    Script to download several columns of a Google Sheets Tab into separate text files

  5. 5

    Capture data into a new tab before script clears columns (Google Sheets)

  6. 6

    Google sheets script to sort rows imported from another tab by column

  7. 7

    Problems with google sheets auto hide rows script running over and over

  8. 8

    Running multiple sheets under one google script, syntax error

  9. 9

    pre-loading custom functions when running sheets daily script

  10. 10

    Copy and Paste google sheets to another google sheets when specific tab is edited

  11. 11

    Google Sheets Completely exclude duplicates

  12. 12

    Exclude sheets when looping through sheets

  13. 13

    Error in Google App Script when submitting form data to Google Sheets

  14. 14

    setName when exporting a PDF from Google Sheets with Google Apps Script

  15. 15

    Keeping script running when tab is not the focus. (JS)

  16. 16

    How to commit changes made in active cell before running script? (Google Sheets / Google Apps Script)

  17. 17

    google script to keep a running total when updated

  18. 18

    Trying to fetch data from Google Sheets using Google script and displaying on web page having horizontal tab

  19. 19

    How do I exclude certain sheets/tabs from google app script?

  20. 20

    onChange specify tab google sheets

  21. 21

    Linking to another tab in Google Sheets

  22. 22

    Dynamic Tab linking in Google Sheets

  23. 23

    Google Sheets Custom Script

  24. 24

    Sharing Google Sheets with script

  25. 25

    Google Sheets Script getLastRow

  26. 26

    Google Sheets Script - Checkbox

  27. 27

    Finetune google sheets script

  28. 28

    Google Sheets Script Approval

  29. 29

    Google Sheets - Script to “Replace” instead of “Create”, when file name is the same

HotTag

Archive