Range PasteSpecial error

  • Thread starter Thread starter Cantru
  • Start date Start date
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
 
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
 
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?
 
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
 
Thanks JB. The .Value option will not work for me in this case. But it opens
my mind for other possibilites. Thanks again.
 
Back
Top