1
votes

I am trying to run the following code line of code (taken from https://developers.google.com/apps-script/reference/spreadsheet/range#copyTo(Range,Object)):

sheet.getRange("D1:D").copyTo(sheet.getRange("D1"), {contentsOnly:true});

I am getting the error "We're sorry, a server error occurred. Please wait a bit and try again."

It runs without a problem if I run the code without the contentsOnly bit:

sheet.getRange("D1:D").copyTo(sheet.getRange("D1"));

I am attempting to copy > paste values as I want to remove the formula that is in the cells.

I thought it could be that I had a Spreadsheet and not a Sheet (I was using openById, whereas the example uses getActiveSheet), but when I added getSheetbyName() to get a sheet instead, I still got the same error.

1

1 Answers

4
votes

copyTo is intended to copy on another range, I guess the error you get is normal...

You can get the result you want with getValues() / setValues()

var values = sheet.getRange("D1:D").getValues();
sheet.getRange("D1:D").setValues(values);

EDIT :

Following Adam's comment (thanks) it appears that the copyTo method should work in this case too, take my suggestion as a workaround if it doesn't for you (even if it was probably only a temporary issue)