PDA

View Full Version : Copying from one file to another



sanjeev
09-22-2009, 07:07 AM
Okay, here is what I need if anyone can help. I get a file everyday named "Forecast" that has 100 sheets with consistant names (Augusta, Columbia, etc.). I have another file named "Gameplan" that has data that has 2 columns that need to be cut and pasted to each sheet in Forecast. I can setup the data in two ways-have a sheet in Gameplan with identical name as Forecast or have one sheet that has headers with the name of the Forecast sheet in row 1. Of the 100 sheets in the Forecast, sometimes a couple are missing, so we want to avoid errors.

Thank you so much.

Bob Phillips
09-22-2009, 08:09 AM
Untested


For Each sh In Workbooks("Forecast").Worksheets

Worksheets("Gameplan").Columns("A:B").Copy sh.Range("A1")
Next sh

sanjeev
10-29-2009, 06:21 AM
this does no seem to work, gives a debug error. do i need to define sh or something?

Saladsamurai
10-29-2009, 06:40 AM
this does no seem to work, gives a debug error. do i need to define sh or something?

Yes. Dim sh As WorkSheet I believe.

sanjeev
10-30-2009, 04:19 AM
It still gives error with workshhetts line

Aussiebear
10-30-2009, 03:09 PM
Please post a sample workbook with your code as it currently stands.

RolfJ
10-30-2009, 10:10 PM
Reading this thread gives me the impression that somebody fell asleep behind the wheel!

Sanjee said in his post that he had workBOOKS (i.e. 'files') with the name "Gameplan" and "Forecast", not a workSHEET with the name "Gameplan". In addition, nobody told him that both workbooks need to be open for the code provided to work.

So here is my attempt to help out.

Assumptions:

Both workbooks, "Gameplan" and "Forecast" are open in Excel.
The workbook "Gameplan" has only one worksheet 'Sheet1'
The following code can reside in either one of these two workbooks (or even in a third workbook that is not participating in the process)
Dim sh As Worksheet
For Each sh In Workbooks("Forecast.xls").Worksheets
Workbooks("Gameplan.xls").Worksheets("Sheet1").Columns("A:B").Copy sh.Range("A1")
Next sh