Why doesn't VBA let me paste a copied selection???

perezpa

New Member
Joined
Jun 17, 2011
Messages
17
Here is the piece of code I am working with:

Code:
For row = 1 To 25
                If Left(wsRes.Cells(row, 1).Value, 2) = "MC" Or Left(wsRes.Cells(row, 1).Value, 2) = "LS" Then
                    wsRes.Cells.Range("A" & row, "J" & row).Copy
                    wsdata.Range("Table1[Centro]").ListObject.ListRows.Add (1)
                    wsdata.Range("A5").PasteSpecial Paste:=xlPasteValues
                    wsdata.Cells(5, 11).Value = MyYear
                    wsdata.Cells(5, 12).Value = MyMonth
                    If MyYear = 2008 Or MyYear = 2009 Or (MyYear = 2010 And MyMonth < 4) Then
                        Range("H5:I5").Cut Destination:=Range("I5:J5")
                    End If
                End If

I get an error message saying that the Paste method failed on the range or something like that. I am copying a range from wsRes and pasting it in a table located in wsdata. Why is this happening???

Thank you for the help in advance.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
The copy is cleared before you paste.

Try something like this...
Code:
                    wsdata.Range("Table1[Centro]").ListObject.ListRows.Add (1)
                    wsRes.Cells.Range("A" & row, "J" & row).Copy
                    wsdata.Range("A5").PasteSpecial Paste:=xlPasteValues

Or just this...
Code:
                    wsdata.Range("Table1[Centro]").ListObject.ListRows.Add (1)
                    wsdata.Range("A5:J5").Value = wsRes.Cells.Range("A" & row, "J" & row).Value
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

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