ERROR:Copy Paste Areas are different

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

Code:
Range("A4:A3").Select        Range(Selection, Selection.End(xlToRight)).Copy
        COM.Worksheets(G).Activate
        Range("A2").Select
        Selection.End(xlToRight).Offset(-1, 1).Select
        Selection.PasteSpecial Paste:=xlPasteValues


I am receiving an error message that is saying the copy range is not able to paste. The area to be copied is a rectangle. I would like the paste range to be a single cell. How to grab only the cell at the offset point?

Thanks!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Paste it to the single top left cell.

Code:
Range("A3:A4").Select
Range(Selection, Selection.End(xlToRight)).Copy
COM.Worksheets(G).Range("A2").PasteSpecial Paste:=xlPasteValues

I have put it as A2 although looking at your code it looks like you are trying to start it in A1 so change it if necessary or use the below (although I can't see a good reason to not refer directly to the cell with what you have posted)...


Code:
Range("A3:A4").Select
Range(Selection, Selection.End(xlToRight)).Copy
COM.Worksheets(G).Range("A2").offset(-1).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Hmmmm...

The error message I am receiving says

"Runtime Error 1004: The information cannot be pasted because the Copy area and the paste area are not the same size and shape. Try one of the following: click a single cell and then paste select a rectangle thats the same size and shape, and then paste. "

could the copied rectangle be creating problems for the paste area due to the way I selected the range for copy? I used A4:A3 instead of the other way around because I want the xltoRight function to run along the A4 row instead of the 3rd row.

I would still like the pasted material to be pasted from the top left corner however, I don't think I've seen any other paste method from a different reference point.
 
Upvote 0
Are you pasting to a single cell as I posted? what is your variable G in Worksheets(G) and what is your variable COM?

Post your actual code where you are defining G and COM.
 
Upvote 0
well that one worked....ill try once more

I would like to set the target cell for pasting using the End method so that in case the number of columns changes in the future I won't have to rewrite it.

here are the lines that define the variables

Code:
Set COM = Workbooks("COMM_COMBINED.xls")

Code:
For Each Worksheet In PA.Worksheets    
    
    G = ActiveSheet.Name

lets see if this works...Thanks!
 
Upvote 0
ERROR: PasteSpecial Method of Range Class Failed

I am receiving the "PasteSpecial Method of Range Class failed" but I can't figure out why. The lower of the two lines in the code is recording the error.

Code:
COM.Worksheets(G).Activate
        Range("A2").End(xlToRight).Offset(-1, 1).PasteSpecial Paste:=xlPasteValues

Thanks!
 
Last edited by a moderator:
Upvote 0
This

Code:
For Each Worksheet In PA.Worksheets    
    
    G = ActiveSheet.Name

Should probably be

Code:
For Each Worksheet In PA.Worksheets    
    
    G = Worksheet.Name

Although you shouldn't (whether a reserved word or not) use Worksheet as a name for a variable as it used by VBA and so is liable to confuse it (and if it is in the list of reserved words it will throw an error), better to use something like...

Code:
Dim ws as Worksheet
' other code if needed
For Each ws In PA.Worksheets    
    
    G = ws.Name

Personally I would leave the variable as a worksheet object rather than use a string conversion.


I would like to set the target cell for pasting using the End method so that in case the number of columns changes in the future I won't have to rewrite it.

If you are talking about the number of columns in the copy range changing then that doesn't affect the paste destination if you are using a single cell as the destination and you wouldn't need to re-write it for that.

If you are talking about the destination cell then (guessing a bit here as you haven't described it) then I would use.

Code:
COM.Worksheets(G).Cells(2, Columns.count).End(xlToLeft).Offset(-1, 1).PasteSpecial Paste:=xlPasteValues

This assumes that your Offset and row number originally was correct.
 
Last edited:
Upvote 0
Re: ERROR: PasteSpecial Method of Range Class Failed

What did you copy? If you copied an entire column, you could get that error. Can you show all the code?
 
Upvote 0
Re: ERROR: PasteSpecial Method of Range Class Failed

Code:
Range("A4").Select
        Range(Selection, Selection.End(xlToRight).Offset(-1, 0)).Copy

these are the copy lines...just to clarify I have the offset here too. my intention is to copy a rectangle two rows by the selection end(xltoRight) wide
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,636
Members
452,662
Latest member
Aman1997

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