Home > Mobile >  having trouble with a simple copy and paste function in google scripts
having trouble with a simple copy and paste function in google scripts

Time:01-07

i'm trying to call a function from the menu bar to copy a set of values in google sheets to an "archive" tab. The error i'm getting is "Exception: The parameters (SpreadsheetApp.Range) don't match the method signature for SpreadsheetApp.Range.setValues." here is the code:

function archiveCompleted () {
 var spreadsheet = SpreadsheetApp.getActive();
 var copyFrom = spreadsheet.getSheetByName("completed autofill");
 var copyDest = spreadsheet.getSheetByName("Completed Orders");
 var sourceRange = copyFrom.getRange(1,1,copyFrom.getLastRow(),copyFrom.getLastColumn());
 var destRange = copyDest.getRange(copyDest.getLastRow()   1,1,copyFrom.getLastRow(),copyFrom.getLastColumn()); 
 //1,1,copyFrom.getLastColumn());
 sourceRange.copyValuesToRange(destRange);
 spreadsheet.setActiveSheet(spreadsheet.getSheetByName('Copy From Feildpine'),true);

}

thanks for any help!

CodePudding user response:

I thought that about your error message of Exception: The parameters (SpreadsheetApp.Range) don't match the method signature for SpreadsheetApp.Range.setValues., unfortunately, I cannot find setValues in your showing script. So I'm worried that you miscopied your current script.

But, when I saw your script, I thought that sourceRange.copyValuesToRange(destRange); is required to be modified. Because the arguments of copyValuesToRange are gridId, column, columnEnd, row, rowEnd or sheet, column, columnEnd, row, rowEnd. Ref1, Ref2

So, in this modification, I would like to propose modifying the line as follows.

From:

sourceRange.copyValuesToRange(destRange);

To:

sourceRange.copyTo(destRange, {contentsOnly: true});

Reference:

  •  Tags:  
  • Related