Solved

copy contents from one sheet to another worksheet of another workbook

Posted on 2013-11-11
7
285 Views
Last Modified: 2013-12-01
Hi Experts,

I tried to copy one work sheet sheet1 to another worksheet but getting runtim error:

"Object does not support this property of method"


Set ws_Source_02 = wb_Source_01.Sheets("Sheet1")
Set ws_Source_03 = wb_Source_02.Sheets("Template")

ws_Source_03("Template").Cells.Copy Destination:=ws_Source_02("Sheet1").Cells

Would you please advise how to fix to get rid of this error.

Thanks
0
Comment
Question by:alam747
  • 4
  • 3
7 Comments
 

Author Comment

by:alam747
ID: 39640608
I tried this :

ws_Source_03.Cells.UsedRange.Copy ws_Source_02.Cells.Range("A1")

getting same run time error.
0
 
LVL 80

Expert Comment

by:byundt
ID: 39640734
I'm guessing that ws_Source_03 and ws_Source_02 are both Dim as Worksheet. If so, then you might try:
ws_Source_03.Cells.Copy Destination:=ws_Source_02.Cells(1, 1)

Open in new window

The above statement copies the formats, formulas & values on the Template sheet onto Sheet1. Did you really mean to wipe out any data that had been on Sheet1? Or were you really wanting to apply the formats from Template to Sheet1. In such a case you might do:
ws_Source_03("Template").Cells.Copy 
ws_Source_02("Sheet1").Cells(1, 1).PasteSpecial xlPasteFormats

Open in new window

0
 

Author Comment

by:alam747
ID: 39641374
I want data and the format,
First code copies the data but not the cell format such as cell width, cell etc.

Second code only copies the format after I changed to:
ws_Source_03.Cells.Copy
ws_Source_02.Cells(1, 1).PasteSpecial xlPasteFormats

because, if I use as is got the same run time error mentioned.

To copy both data and format what will be code.

Please advise.

Thanks
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 80

Expert Comment

by:byundt
ID: 39641396
My goof on not deleting the "Sheet1" and "Template" from the second example.

Do you want to copy formulas, or just values?
ws_Source_03.Cells.Copy
ws_Source_02.Cells(1, 1).PasteSpecial xlPasteAll    'Formats, formulas and values
ws_Source_02.Cells(1, 1).PasteSpecial xlPasteValues     'Overwrite formulas with the values they originally returned

Open in new window

0
 

Author Comment

by:alam747
ID: 39644397
if I want to add formula to one of cell after assign other cell value such as:

ws_Source_02.Cells(2,3) = 40
ws_Source_02.Cells(2.4) = 20

how can I assign a formula in ws_Source_02.Cells(e:e)   like =C2-d2

please advise

Thanks
0
 
LVL 80

Accepted Solution

by:
byundt earned 500 total points
ID: 39644659
Here are a few alternatives:
Sub test()
Dim ws_Source_02 As Worksheet
Set ws_Source_02 = ActiveSheet
ws_Source_02.Range("E2").Formula = "=C2-D2"
With ws_Source_02
    .Range(.Cells(2, 5), .Cells(.Cells(.Rows.Count, 4).End(xlUp).Row, 5)).Formula = "=C2-D2"
    .Range("E:E").FormulaR1C1 = "=RC[-2]-RC[-1]"
End With
End Sub

Open in new window

0
 

Author Closing Comment

by:alam747
ID: 39688883
Thanks
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now