Solved

copy contents from one sheet to another worksheet of another workbook

Posted on 2013-11-11
7
293 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
To Patch or not to Patch? That is the question!

Don't get caught out like thousands of others around the world in the recent Ransomware Fiasco!
Discuss..
- Why it's not a good idea to wait before Patching
- Sensible approaches to Patching discussed
- Add your feedback, comments and suggestions

 
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

RoboForm Secure Password Management System

RoboForm Everywhere - Superb Browser Support
Windows / Apple / IOS / Android / Linux / Chrome OS
Use different complex passwords everywhere
Best Secure Password Management by far
Synchronize all of your devices instantly
Safe, Secure & Highly Recommended!

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

734 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