ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Range PasteSpecial error (https://www.excelbanter.com/excel-programming/435533-range-pastespecial-error.html)

Cantru

Range PasteSpecial error
 
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

Tom Hutchins

Range PasteSpecial error
 
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

"Cantru" wrote:

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


JBeaucaire[_131_]

Range PasteSpecial error
 
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?

--
"Actually, I *am* a rocket scientist." -- JB
(www.MadRocketScientist.com)

Your feedback is appreciated, click YES if this post helped you.


"Cantru" wrote:

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


Cantru

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

"Tom Hutchins" wrote:

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

"Cantru" wrote:

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


Cantru

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

"JBeaucaire" wrote:

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?

--
"Actually, I *am* a rocket scientist." -- JB
(www.MadRocketScientist.com)

Your feedback is appreciated, click YES if this post helped you.


"Cantru" wrote:

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



All times are GMT +1. The time now is 12:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com