Solved

copy contents from one sheet to another worksheet of another workbook

Posted on 2013-11-11
7
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

617 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