VBA Paste Special Error Message after running macro twice

Will85

Board Regular
Joined
Apr 26, 2012
Messages
240
Office Version
  1. 365
Platform
  1. Windows
I am not sure why I am getting this error

PasteSpecial Method of Range Class Failed

My macro is activated while on sheet Control, it copies data from sheet Control and pastes it on sheet CY, then it goes back to sheet Control and clears out the old data.

If I immediately run the macro again, I get the error. If I change a single piece of the data I dont get the error. It wouldnt really make sense to immediately run the macro, but I am trying to manage what a user might do on accident.

I neve know when to use Application.CutCopyMode = False but adding it in here makes no difference.


Sub Test()
ActiveSheet.Unprotect
Range("E1:N1").Select
Selection.Copy

Sheets("CY").Select
ActiveSheet.Unprotect
Range("B" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
ActiveSheet.Protect

Sheets("Control").Select

Range("C1").Value = "N"

Range("C2,C5:C6,A10,C10,A14,C14,C16:C18").Select
Selection.ClearContents
ActiveSheet.Protect


End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Can you see if you get the same issue with the code below

VBA Code:
Sub Test2()
   Sheets("Control").Unprotect
   Sheets("Control").Range("E1:N1").Copy

    With Sheets("CY")
        .Unprotect
        .Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
        .Protect
    End With

    With Sheets("Control")

        .Range("C1").Value = "N"

        .Range("C2,C5:C6,A10,C10,A14,C14,C16:C18").ClearContents
        .Protect

    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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