title: How do I automatically archive a google sheet with a google script?
body: <p>I have a google sheet that is scraping data from a table from an html homepage.</p>
  
  <p>The data is in a simple google sheet with A1:H1 containing the headers/labels and A2:H2 containing the values</p>
  
  <p>Every time that data changes, every time my google sheet is updated with new data, I want the new data from A2:H2 to be "archived"/copied automatically to another google (sub)sheet. </p>
  
  <p>Apparently, I can do this with a Google Script (that is then run automatically every day with a trigger) - I tried to use this tutorial here: <a href="https://www.computerworld.com/article/2469616/business-intelligence/business-intelligence-79661-how-to-create-an-automatically-updating-spreadsheet.html#slide7" rel="nofollow noreferrer">https://www.computerworld.com/article/2469616/business-intelligence/business-intelligence-79661-how-to-create-an-automatically-updating-spreadsheet.html#slide7</a></p>
  
  <p>The code they have/give is:</p>
  
  <pre><code>function storeData(){
  var datarange = sheet.getDataRange();
  var numRows = datarange.getNumRows();
  var numColumns = datarange.getNumColumns();
  var nextColumn = numColumns + 1;
  sheet.getRange(1,nextColumn).setValue(new Date());
    for (var i=2; i &lt;= numRows; i++){
  var numLikes = sheet.getRange(i, 3).getValue();
  sheet.getRange(i, numColumns + 1).setValue(numLikes);
  }
  }
  </code></pre>
  
  <p>When I run this I get the following error: "sheet" is not defined</p>
  
  <p>So, do I need to put in the data range I want to copy between ()? Like this?</p>
  
  <pre><code>function storeData(){
  var datarange = sheet.getDataRange(A2:H2);
  var numRows = datarange.getNumRows();
  var numColumns = datarange.getNumColumns();
  var nextColumn = numColumns + 1;
  sheet.getRange(1,nextColumn).setValue(new Date());
    for (var i=2; i &lt;= numRows; i++){
  var numLikes = sheet.getRange(i, 3).getValue();
  sheet.getRange(i, numColumns + 1).setValue(numLikes);
  }
  }
  </code></pre>
  
  <p>When I run this I get the following error: missing ")" sign in line 2</p>
  
  <p>Can somebody help?</p>