Google-sheets – How to use a script across multiple pages of a Google Sheet

google sheetsgoogle-apps-script

I'll start by saying I'm very new to this. Here's my problem. I have a GoogleSheet I created to use as a seating chart in my classes. It is designed so that when I click the blue check button the cell where a child's name will appear turns green. It can then be reset by clicking the recycle button in the corner. All of that works fine but only on the first tab of the sheet. I would like to use it across all six tabs, one for each class I teach. Can anyone show me how to share the script across all six sections.
Here is the basic code I used:

function A3Green() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheets()[0];

  var colors = [
    ["#00ff40"]// These are hex equivalents
  ];

   var cell = sheet.getRange("A3:A3");
   cell.setBackground (colors);
}

Best Answer

The script is already "shared across" all the sheets in the workbook. The 0 on the following line returns the first sheet

var sheet = ss.getSheets()[0];

You could replace the 0 by 1 to get the second sheet, by 2 to get the third sheet and so on.

Reference