4

I have a script which copies new form data from one sheet to another. However, I only want the values and not the formatting to paste.

Here is the script:

function onFormSubmit() {
  // moves a row from a sheet to another when a magic value is entered in a column
  // adjust the following variables to fit your needs
  // see https://productforums.google.com/d/topic/docs/ehoCZjFPBao/discussion

  var sheetNameToWatch = "Form Results";

  var sheetNameToMoveTheRowTo = "Job List";

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = SpreadsheetApp.getActiveSheet();
  var range = sheet.getActiveCell();


  if (sheet.getName() == sheetNameToWatch && range.getColumn()) {

    var targetSheet = ss.getSheetByName(sheetNameToMoveTheRowTo);
    var targetRange = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
    sheet.getRange(range.getRow(), 1, 1, 
      sheet.getLastColumn()).copyTo(targetRange), {contentsOnly:true};
  }
}

Any ideas?

1
  • 1
    What's the syntax of copyTo method?
    – TheMaster
    Jun 22, 2018 at 17:16

1 Answer 1

4

Your last line has a mislaid close-paren. Rather than:

sheet.getRange(range.getRow(), 1, 1, 
  sheet.getLastColumn()).copyTo(targetRange), {contentsOnly:true};

the copyTo "options"-object parameter must be inside the function's parameter list:

sheet.getRange(range.getRow(), 1, 1, 
  sheet.getLastColumn()).copyTo(targetRange, {contentsOnly:true});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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