Macro works in Excel 2013 but not in 2016, Run-time error '1004'

AK_Caveman

New Member
Joined
Apr 12, 2018
Messages
2
I am a complete noob to VBA. We have a macro that runs fine on Excel 2013 but gets a Run-time error on 2016. The part of the macro where it hangs up is trying to copy and paste merged cells. The error states "To do this, all merged cells need to be the same size." They are the same size. It appears to have no issues copying, just pasting into the new spreadsheet. Here is the code:

Code:
    Workbooks("rmgr-update.xlsm").Activate
    Sheets("Sheet2").Select
    Range("a1:a2").Copy
    Workbooks(pasteFile).Activate
    Sheets("Template").Select
    Range("a1:a2").PasteSpecial Paste:=xlPasteValues

It errors on the last line.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How sure are you that they are the same size? The error message would suggest they are not.

Code:
'Check size of merged ranges
Sub MergedCheck()    
    Dim S As String
    Dim R As Range
    S = ""
    For Each R In Workbooks("rmgr-update.xlsm").Sheets("Sheet2").Range("a1:a2")
        If R.MergeCells Then
            S = S & " Cell " & R.Address(External:=True) & " is part of a merged range (" & R.MergeArea.Address & ")" & vbCr
        End If
    Next R
    For Each R In Workbooks(pasteFile).Sheets("Template").Range("a1:a2")
        If R.MergeCells Then
            S = S & " Cell " & R.Address(External:=True) & " is part of a merged range (" & R.MergeArea.Address & ")"
        End If
    Next R
    If S = "" Then
        S = "No merged cells found"
    End If
    MsgBox S
End Sub
 
Last edited:
Upvote 0
I know they are the same size because, it works fine and 2013 and when I step through the code and compare the 2 sheets they are the same. a1:n1 and a2:n2
 
Upvote 0
Did you run the macro I posted in #2 ? It will confirm whether or not merged cell areas are the same size.

I ran a variation of your code under both Excel 2010 and Excel 2016. It worked in both places. The only time it DIDN'T work was when I made the merged cells different sizes. I suggest that you perform an experiment where you un-merge all cells in both the copy and paste ranges
Workbooks("rmgr-update.xlsm").Sheets("Sheet2").Range("a1:a2")

Workbooks(pasteFile).Sheets("Template").Range("a1:a2")​

And see your if macro will perform the copy/paste. If it does you can merge the cells again, taking care to see that the merged areas are the same size.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top