Range PasteSpecial error

C

Cantru

Why does the following line doesn't work but, when you split it does?

Range("B8").Copy Range("DefYear").PasteSpecial (xlPasteValues)

Range("B8").Copy
Range("DefYear").PasteSpecial (xlPasteValues)

Whre DefYear is the name of a cell.

Thanks
 
T

Tom Hutchins

Copy and PasteSpecial are two separate statements, so they would normally be
on separate lines. To put multiple statements on a single line you must
separate them with a colon. Try this:

Range("B8").Copy: Range("DefYear").PasteSpecial (xlPasteValues)

You can specify the destination as an optional parameter for the Copy
command, but when you add .PasteSpecial it becomes a separate statement.

Hope this helps,

Hutch
 
J

JBeaucaire

Beacause you can't pass parameters to an inline destination. In a separate
line you can construct a full paste command with parameters, just like you've
discovered.

You could invert the logic and use the .Value option to strip the formula:

Range("DefYear").Value = Range("B8").Value

Does that work for you?
 
C

Cantru

Thanks Hutch, it's clear to me how excel works.

Tom Hutchins said:
Copy and PasteSpecial are two separate statements, so they would normally be
on separate lines. To put multiple statements on a single line you must
separate them with a colon. Try this:

Range("B8").Copy: Range("DefYear").PasteSpecial (xlPasteValues)

You can specify the destination as an optional parameter for the Copy
command, but when you add .PasteSpecial it becomes a separate statement.

Hope this helps,

Hutch
 
C

Cantru

Thanks JB. The .Value option will not work for me in this case. But it opens
my mind for other possibilites. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top