title: Google Sheets Script to return sheet name will not automatically update on creating a new sheet
body: <p>I have written a script in Google Sheets to return the name of a given sheet (see below).</p>
  
  <p>The function is written into a summary sheet, where the input given as the index of the sheet required. I have all the functions pre-written e.g. </p>
  
  <p>A1 = GetSheet(1) B1 = GetSheet(2) C1 = GetSheet(3) ...etc</p>
  
  <p>Obviously, when the sheet with the index in question does not yet exist, I get an error. However, when I do create that sheet, the cell does not automatically update with the name of the new sheet, it still returns an error. To get the name to appear, I have to delete the function and re-paste it in.</p>
  
  <p>Is there a way for the cells to automatically update when a new sheet is added, without re-typing the function?</p>
  
  <p>Apologies if I am missing something obvious, I am very new to this!</p>
  
  <pre><code>function GetSheet(input)
  {
    var spread = SpreadsheetApp.getActiveSpreadsheet();
    var sourceSheet = SpreadsheetApp.getActiveSheet();
    var sourceIndex = sourceSheet.getIndex();
    var nextIndex = sourceIndex + 1;  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    SpreadsheetApp.setActiveSheet(ss.getSheets()[input]);        
    var active = ss.getActiveSheet();
    var name = active.getName();                                   
    return name
  }
  </code></pre>