Compile Error on Paste

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Compile Error on Paste

Post by jstevens »

I'm encountering a compile error using the following code. The error message I'm receiving is: "Compile Error - Expected: End of Statement".
untitled.png
As far as I can tell, it should work.

Thank you for taking a look,
John
You do not have the required permissions to view the files attached to this post.
Regards,
John

User avatar
HansV
Administrator
Posts: 78671
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Compile Error on Paste

Post by HansV »

You're mixing two different operations in one instruction.

You can combine a copy and a normal paste operation in one instruction:

oCurWB.Sheets("Sheet1").Range("A10").CurrentRegion.Offset(1, 0).Copy Destination:=oNewWB.Sheets("Sheet1").Range("A8")

But for Paste Special you need to perform the copy and pastes operation in separate instructions:

oCurWB.Sheets("Sheet1").Range("A10").CurrentRegion.Offset(1, 0).Copy
oNewWB.Sheets("Sheet1").Range("A8").PasteSpecial Paste:=xlPasteValues

(I omitted the other three arguments since you provided the default values)

As you have found out, you can't combine these into one instruction.
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Compile Error on Paste

Post by jstevens »

Thanks Hans,

I came to that conclusion but needed to hear it from someone else.

Regards,
John
Regards,
John