title: How to write array to sheets column and add custom formula to column next to it using google apps script?
body: <p>Here's the problem:</p>
  <p>Get a list of tickers from a column in a sheet (LIST OF STOCKS)</p>
  <p>Push it, so as each ticker appears in the array 105 times</p>
  <p>Write the resulting array to another sheet's column (TickersData)</p>
  <p>Next to the first ticker each element brought to TickersData, add the formula.</p>
  <p>Here's the code, where I could get up to repeating the values within an array, but can't write them to the other sheet:</p>
  <pre><code>function getGFTickersData() {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;LIST OF STOCKS&quot;);
    var tickerRng = ss.getRange(2, 1, ss.getLastRow(), 1).getValues();
    var TDSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(&quot;TickersData&quot;);
    var startRow = 2;
    var tickerArr = [];
  
    for (var b = 0; b &lt; tickerRng.length; b++) {
      var tickerToArr = tickerRng[b];
      if (tickerRng[b] != '') {
        var repeated = [].concat(... new Array(104).fill([tickerToArr]));
        tickerArr.push(repeated);
      }
    }
    Logger.log(tickerArr.length);
  
    TDSheet.getRange(TDSheet.getLastRow() + 1, 1, tickerArr.length, 1).setValues(tickerArr);
  
    var targetRow = TDSheet.getRange(&quot;B:B&quot;).getValues();
    var maxIndex = targetRow.reduce(function (maxIndex, row, index) {
      return row[0] === &quot;&quot; ? maxIndex : index;
    }, 0);
  
    var row = TDSheet.getRange(maxIndex + 2, 2).setFormula(&quot;=query(googlefinance(&quot; + '&quot;' + tickerArr + '&quot;' + &quot;,'all shares'!A4,'all shares'!D3,'all shares'!D4,'all shares'!D5),&quot; + '&quot;' + &quot;select *&quot; + '&quot;' + &quot;,1)&quot;);
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Ni4a4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ni4a4.png" alt="The logs" /></a></p>
  <p>Here's an image of one ticker as an example. After 105 rows, there should be a new ticker in column A and the formula added next to it in column B:
  <a href="https://i.stack.imgur.com/kXVIi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kXVIi.png" alt="enter image description here" /></a></p>