2
votes

I'm using Sheet.CopyTo to copy a range of cells from one sheet to another and I'm getting the error "Your paste overlaps with merged cells. Please unmerge the cells and try again.". The range I'm pasting contains merged cells but the range I'm pasting to is on a totally blank sheet with no merges. In other cases where the source range has merged cells copyTo works fine. Doing the same paste from the UI works fine.

Here is my code:

function test()
{
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var src = ss.getSheetByName('Src');
  var srcRange = src.getRange('F2:W2');
  var dst = ss.getSheetByName('Dst');
  var dstRange = dst.getRange('F2');
  srcRange.copyTo(dstRange);
}

Public version of the spreadsheet is at:

https://docs.google.com/spreadsheet/ccc?key=0AmjukMc-vZIEdEtyYk53VlpWMEV3Y0l5THQ1OFBJSUE

1

1 Answers

1
votes

Problem was that the destination sheet didn't have enough columns to fit the data being copied. Using paste from the UI adds in the new columns automatically but with copyTo you have to do it yourself using insertColumns before the copyTo. The error message is very misleading.