title: I need to add formula to the same cell in all of the sheets in a google sheets workbook
body: <p>I have a workbook that contains around 150 sheets and I’m trying to create an index of all of the sheets with a hyperlink from the index to each of the individual sheets. </p>
  
  <p>In the index sheet i have a list of all the sheet names in column A and the formula INDIRECT("’"&amp;A1&amp;"'!AF1”) in column B. Then in cell AF1 of each sheet i have used script (I’ve posted this script below) to populate this cell with the spreadsheetID (URL + ID) of that spreadsheet. </p>
  
  <p>Now i have the problem of adding the formula "=sheetURL()” to cell AF1 of all sheets in my workbook without having to do so manually.</p>
  
  <pre><code>function sheetURL()
  {
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getActiveSheet().getSheetId();
  
   return ss.getUrl() + '#gid=' + sheet;
  }
  </code></pre>