Run-time error '1004': PasteSpecial Method of Range class failed

vbalearner11

New Member
Joined
Jan 19, 2018
Messages
18
I have a very large program and i am getting error when running. Can somebody please help me how to fix this problem. Getting error when it is pasting to "D1" Error message says: Run-time error '1004' You can't paste this here because the Copy area and paste area aren't the same size select just one cell in the paste area or an area that's the same size, and try pasting it again.
Here's the code as follows


<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">If lastROWduplicate >1Then
Range
(Cells(2,1), Cells(lastROWduplicate,1)).SpecialCells(xlCellTypeVisible).Select
Selection
.Copy
Range
("D1").PasteSpecial xlPasteValues '--->>> This line throws error
OnErrorResumeNext
DuplicateWKSHT
.ShowAllData
OnErrorGoTo0
lastROWduplicate
= DuplicateWKSHT.Cells(DuplicateWKSHT.Rows.Count,"D").End(xlUp).Row
DuplicateINX
=1
DuplicateProjects
=""
For DuplicateINX =1To lastROWduplicate
DuplicateProjects
= DuplicateProjects & Chr(10)&CStr(Range("D"& DuplicateINX).Value)
If DuplicateINX = lastROWduplicate Then
MsgBox
("Error! The following project(s) appear at more than once in the Conso for the "& Curr.Name &"tab:"& Chr(10))
EndIf
Next

EndIf</code>
 
Last edited:

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
What is the range of the address you are trying to copy when you get the error?
You can find out like this:
Code:
[COLOR=#101094][FONT=Consolas][FONT=inherit]If[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] lastROWduplicate [/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]>[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]1[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Then[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Range[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]Cells[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]2[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]1[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]),[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] Cells[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]lastROWduplicate[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]1[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit])).[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]SpecialCells[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]xlCellTypeVisible[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]).[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Select
[/FONT][/FONT][/COLOR][COLOR=#ff0000][FONT=Consolas][FONT=inherit][/FONT][/FONT][FONT=Consolas][FONT=inherit]MsgBox Selection.Address[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Selection[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]Copy
Range[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"D1"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]).[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]PasteSpecial xlPasteValues [/FONT][/FONT][/COLOR][COLOR=#858C93][FONT=Consolas][FONT=inherit]'--->>> This line throws error[/FONT][/FONT][/COLOR]
Also, are there any protected or merged cells in the ranges you are copying from/to?
 
Upvote 0
Hello Joe4,

Thank you for your response. You are right there are few rows which are hidden and so it is throwing an error.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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