Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cells().paste VS cells.pastespecial?

Tags:

excel

vba

How come below code works:

.Range("D4:F4").copy
.cells(1,1).PasteSpecial  

While below doesn't work:

.Range("D4:F4").copy
.cells(1,1).Paste  

I realize that the correct syntax is

.Range("D4:F4").copy Destination:=
like image 823
newdimension Avatar asked Aug 05 '15 20:08

newdimension


1 Answers

The answer is very simple .Paste is not a property of the Cells object but of the Worksheet Object

If you type . after the Cells, Intellisense will confirm that fact :)

There are various ways to copy data across.

If you want to only copy values across and not the formatting then this is the best way

rng1.Value = rng2.Value

If you want to carry the formatting then either you can use

Rng1.copy Rng2 

or

Rng1.Copy
rng2.pastespecial
like image 183
Siddharth Rout Avatar answered Sep 22 '22 16:09

Siddharth Rout