VBA Copying Destination

Littlemalky

Board Regular
Joined
Jan 14, 2011
Messages
223
Is there any way to copy all cells and paste destination over all cells in another location so that it replaces whatever was there before and removes the old. For example, something like:

Workbooks("Example.xlsx").Worksheets("Example").Cells.Copy Destination:=Workbooks("Example1.xlsx").Worksheets("Example1").Cells

This never works for me because I believe it wants me to specify a range more specificly, but if i didn't want to clear the page of "Example1.xlsx" before I pasted something in there, is there an easy way to just paste over what was there replacing the contents if the amount of rows/columns differ. I know how to do it line by line, but I want to write it more efficiently.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try, instead, doing:

Workbooks("Example.xlsx").Worksheets("Example").Cells.Copy Destination:=Workbooks("Example1.xlsx").Worksheets("Example1").Range("A1")
 
Upvote 0
Yeah, i understand the specifying the range part, but that won't replace everything that was there prior will it? Say I'm copying from something that has 10 rows, but I'm pasting to a sheet that already has 20 rows of data. If i specify the range like that, it's not going to delete the 10 row difference is it? Like pasting over "ALL" cells would...
 
Upvote 0
It should, since you are selecting ALL of the cells to copy over.

However, you could always clear the contents of all the cells in your second workbook prior to pasting:

Code:
Workbooks("Example1.xlsx").Worksheets("Example1").Cells.ClearContents
Workbooks("Example.xlsx").Worksheets("Example").Cells.Copy Destination:=Workbooks("Example1.xlsx").Worksheets("Example1").Range("A1")
 
Upvote 0
Yeah, I was trying to avoid clearing contents for reasons that I have pivot tables connected to the data.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top