0
votes

Bit of a rookie at this and learning atm. I am using the following script to copy data from one sheet to another in the same Google spreadsheet:

function recordHistory() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName("Cover");
  var source = sheet.getRange("a1:c21");
  var values = source.getValues();
  var sheet2 = ss.getSheetByName("January 2020")
  values [0] [0] = new Date();
  sheet2.appendRow(values [0])
}

Which works fine to copy a single row but does not copy the entire range listed (a1:c21). Now I imagine the problem lies around Row 8 but I am not sure.

Here is the link to the spreadsheet I am using for trying this out:

https://docs.google.com/spreadsheets/d/15pEbNy-PmrGeAmpASRUK2iXIyJPfg43Mm2r6bbiTBuM/edit#gid=1296663899

1
Your issue lies with your .appendRow(), you're only adding one row of data by using values[0].ross
Thought so, so what would be the alternative? If you add values [1] then it copies row 2 and nothing else. What do you add there to copy the entire range?Discorave

1 Answers

1
votes
function recordHistory() {
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getSheetByName("Cover");
  var source = sheet.getRange("a1:c21");
  var values = source.getValues();
  var sheet2 = ss.getSheetByName("January 2020")
  values [0][0] = new Date();
  sheet2.getRange(sheet2.getLastRow()+1,1,values.length,values[0].length).setValues(values);
}