0

I have this little script that's giving me some trouble. I get the following error:

Error Exception: The starting row of the range is too small appendToRecords @ Code.gs:10

What I'm trying to accomplish is to assign cell values(A list of names) from a specific range on one sheet after the last row of a specific column (F) in another sheet.

This is my current code:

function appendToRecords() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sourcesheet = ss.getSheetByName("Assignment");
  var targetSheet = ss.getSheetByName("Review")
  var reportData = sourcesheet.getRange("C4:C13")
                              .getValues();
  var owner = targetSheet.getRange("F1:F").getValues();
  var lastRow = owner.filter(String).lenght;
  //copy data
  targetSheet.getRange(lastRow + 1,1,10,1)
              .setValues(reportData);

};

Any help would be greatly appreciated!

1
  • 1
    Welcome to [webapp.se]. There is a typo... instead of lenght use length
    – Rubén
    Apr 6 at 22:50

1 Answer 1

0

There are several ways to solve this, depending on the details of your data.

The quick fix is to correct the typo in lenght. That will not work correctly, though, when column Review!F1:F contains blank values in between other values.

The better quick fix is to use Sheet.appendRow(), in a forEach loop.

The fix I would recommend, however, would be to use the the appendRows_() utility function.

1
  • Thank you for your response! I guess I shouln't even try to code before my morning coffee. The typo was the issue all along and since there should not be any blank values in that column it will do for now. That being said, I will definitely look into using appendRows() for this. Again, thanks a lot!
    – AaronM
    Apr 7 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.