How to run the same code on different tabs?
<p>I have a bit of code which runs down a table and sends emails when an item reaches its expiry date.</p>

<pre><code>function expiryAlert() {
  // get the spreadsheet object
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  // set the first sheet as active
  SpreadsheetApp.setActiveSheet(spreadsheet.getSheets()[0]);
  // fetch this sheet
  var sheet = spreadsheet.getActiveSheet();

  // figure out what the last row is
  var lastRow = sheet.getLastRow();

  // the rows are indexed starting at 1, and the first row
  // is the headers, so start with row 4
  var startRow = 3;

  // days left column
  var range = sheet.getRange(7,4,lastRow-startRow+1,1 );
  var numRows = range.getNumRows();
  var days_open_values = range.getValues();

  // item number column
  range = sheet.getRange(7, 1, lastRow-startRow+1, 1);
  var item_number_values = range.getValues();

  //Now grab the description number
  range = sheet.getRange(7, 2, lastRow-startRow+1, 1);
  var description_values = range.getValues();

  //Now grab the email addresses
  range = sheet.getRange(7, 7, lastRow-startRow+1, 1);
  var emailAddress_values = range.getValues();

  //Now grab the alert days value
  range = sheet.getRange(2, 2);
  var alert_days_values = range.getValues();

  //Grab the sheet title
  range = sheet.getRange(1,1);
  var title_values = range.getValues();

  //Grab the extra alert message
  range = sheet.getRange(3,2);
  var alert_message_values = range.getValues();

  var msg = "";

  // Loop over the days left values
  for (var i = 0; i &lt;= numRows - 1; i++) {
    var days_open = days_open_values[i][0];
    var alert_days = alert_days_values;
    if(days_open == alert_days) {

      var item_number = item_number_values[i][0];
      var description = description_values[i][0];
      var emailAddress = emailAddress_values[i][0];
      var title = title_values;
      var alert_message = alert_message_values;

      msg = msg + "This is an automated alert for "+title+"\n\nItem number "+item_number+", "+description+", is due to expire in "+days_open+" days. Please ensure it is updated or reviewed.\n\n"+alert_message+"\n\n";

    MailApp.sendEmail(emailAddress,title, msg);
    }
  }

};
</code></pre>

<p>I want to add another tab for a different shift and run the same code on that table.</p>

<p>How can I do that? I have googled and searched and can't find anything to help.</p>

<p>Many Thanks!</p>