title: “This operation requires the merged cells to be identically sized.” when copying a range VBA
body: <p>I have code that copies a range from a sheet in one workbook and pastes it in a sheet in another workbook. The range includes merged cells (I didn't design it). The range it pastes the data is formatted exactly the same as where it is copied from. I tested the VBA by copying it to blank workbooks, and it works. However, when I try to copy it to a the worksheet that already has that same formatting, it gives the “This operation requires the merged cells to be identically sized.” error, and I'm unsure how to get around this. Here is what I have:</p>
  
  <pre><code>Sub testcopying()
  Dim FileNm As Object, Cnt As Integer
  Dim TargetFiles As FileDialog
   Set TargetFiles = Application.FileDialog(msoFileDialogOpen)
   With TargetFiles
   .AllowMultiSelect = True
   .Title = "Multi-select target data files:"
   .ButtonName = ""
   .Filters.Clear
   .Filters.Add "*.xls* files", "*.xls*"
   .Show
   End With
  If TargetFiles.SelectedItems.Count = 0 Then
   MsgBox "PICK A FILE!"
   Exit Sub
   End If
  'On Error GoTo below
  Application.ScreenUpdating = False
  Application.DisplayAlerts = False
  
  For Cnt = 1 To TargetFiles.SelectedItems.Count
   'open the file and assign the workbook/worksheet
  Set FileNm = Workbooks.Open(TargetFiles.SelectedItems(Cnt))
  
  ThisWorkbook.Sheets("Vendor Data Sheets").Range("A1:AJ191").Copy
  
  Workbooks(FileNm.Name).Sheets("Sheet1").Range("A1").PasteSpecial xlPasteValues
  
  Application.CutCopyMode = False
  
  Workbooks(FileNm.Name).Close SaveChanges:=True
  Next Cnt
  below:
  Application.DisplayAlerts = True
  Application.ScreenUpdating = True
  If Err.Number &lt;&gt; 0 Then MsgBox "File Error"
  End Sub
  </code></pre>
  
  <p>Any thoughts? I think I may have to write it so it unmerges every cell before pasting the data, then re-merges it, as it was able to successfully paste in the blank workbook (with no merging). But with hundreds of different merged cells, that would take a bit to type up, so I'm hoping there are easier answers. Thanks. </p>