Solved

copy contents from one sheet to another worksheet of another workbook

Posted on 2013-11-11
7
290 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 81

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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 81

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 81

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

791 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