Run time error 1004 - Paste special method of range class failed

Diogenes

New Member
Joined
Apr 2, 2014
Messages
34
Hi all,

I have quite a bizarre error occurring with the code below - when the button is pressed to run this code I get the Run time error 1004 - Paste special method of range class failed. However if I step through the code no error occurs.

The error is occurring at the "paste special" stage of the code.

Could anyone please help explain why it seems to appear when running but not when stepped through and help me to get rid of the error when the button is pressed?

Thanks in advance,

Code:
Sub Remove_duplicates()'
' Remove_duplicates Macro
    Sheets("Working").Visible = True
    Application.GoTo Reference:="All_tbs"
    Selection.Copy
    Range("F4").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    ActiveSheet.Range("$F$4:$G$110145").Removeduplicates Columns:=Array(1, 2), _
        Header:=xlNo
  
  Application.GoTo Reference:="new_tb_codes"
    Selection.Copy
    Sheets("Input").Select
    ActiveSheet.Unprotect
    Range("B26").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveSheet.Protect
   Sheets("Working").Visible = False
        
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Your welcome (just a bit more efficient way of writing it below).

Code:
With Sheets("Input")
    .Unprotect
    .Range("B26").Resize(Range("new_tb_codes").Rows.Count, Range("new_tb_codes").Columns.Count).Value = Range("new_tb_codes").Value
    .Protect
End With
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,842
Members
449,193
Latest member
MikeVol

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