Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to copy n paste as values based on an "instructions" table

Seeking help with a sub to automate repetitive "copy n paste special as
values" from various sheets in a "parent" book into several "child" books'
designated sheets

Example:

V_Wealth.xls
contains sheets named:
0
1
2
3
...
20

v=0.xls
contains sheets named:
0
0 (2)
0 (3)

v=1.xls
contains sheets named:
1
1 (2)
1 (3)

What I need to do (done manually now - tedious & eyeball burning)
[all files above are open simultaneously]

Copy range 1:51* from V_Wealth.xls
Sheetname: 0
*entire rows 1 to 51

then paste as values into same range in
v=0.xls
Sheetname: 0

Then copy range 1:51 from V_Wealth.xls
Sheetname: 1

Paste as values into same range in
v=1.xls
Sheetname: 1

and so on ..

In another book, say: CnP.xls,
thought I could frame up an "instructions" table
in sheet: Z, cols A to E, something like this:

CopyFrom.............Range....In Sheet...PasteTo...In Sheet
V_Wealth.xls........1:51...........0............v= 0.xls.....0
V_Wealth.xls........1:51...........1............v= 1.xls.....1
V_Wealth.xls........1:51...........2............v= 2.xls.....2
V_Wealth.xls........1:51...........3............v= 3.xls.....3
etc

and then run a sub to carry out all the above copy n paste special as values

I'll ensure that all the files concerned: V_Wealth.xls, v=0.xls, v=1.xls,
etc
are opened simultaneously before running the sub

Any insights appreciated. Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sub to copy n paste as values based on an "instructions" table

You can add code to automatically open and close the workbooks.

Sub copy_data()

RowCount = 2
With ThisWorkbook.Sheets("instructions")
Do While .Range("A" & RowCount) < ""

FromBook = .Range("A" & RowCount).Text
FromRows = .Range("B" & RowCount).Text
FromSheet = .Range("C" & RowCount).Text
ToBook = .Range("D" & RowCount).Text
ToSheet = .Range("E" & RowCount).Text

Workbooks(FromBook).Worksheets(FromSheet). _
Rows(FromRows).Copy _
Destination:=Workbooks(ToBook). _
Worksheets(ToSheet).Rows(FromRows)

RowCount = RowCount + 1
Loop
End With
End Su
"Max" wrote:

Seeking help with a sub to automate repetitive "copy n paste special as
values" from various sheets in a "parent" book into several "child" books'
designated sheets

Example:

V_Wealth.xls
contains sheets named:
0
1
2
3
...
20

v=0.xls
contains sheets named:
0
0 (2)
0 (3)

v=1.xls
contains sheets named:
1
1 (2)
1 (3)

What I need to do (done manually now - tedious & eyeball burning)
[all files above are open simultaneously]

Copy range 1:51* from V_Wealth.xls
Sheetname: 0
*entire rows 1 to 51

then paste as values into same range in
v=0.xls
Sheetname: 0

Then copy range 1:51 from V_Wealth.xls
Sheetname: 1

Paste as values into same range in
v=1.xls
Sheetname: 1

and so on ..

In another book, say: CnP.xls,
thought I could frame up an "instructions" table
in sheet: Z, cols A to E, something like this:

CopyFrom.............Range....In Sheet...PasteTo...In Sheet
V_Wealth.xls........1:51...........0............v= 0.xls.....0
V_Wealth.xls........1:51...........1............v= 1.xls.....1
V_Wealth.xls........1:51...........2............v= 2.xls.....2
V_Wealth.xls........1:51...........3............v= 3.xls.....3
etc

and then run a sub to carry out all the above copy n paste special as values

I'll ensure that all the files concerned: V_Wealth.xls, v=0.xls, v=1.xls,
etc
are opened simultaneously before running the sub

Any insights appreciated. Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to copy n paste as values based on an "instructions" table

Many thanks, Joel. That worked marvellously.

You can add code to automatically open and close the workbooks.


Sounds like a good idea.

How would your code look like, assuming all the files listed in the
instructions table are located in, say:

E:\ReRun\Visits Detail Tracking

I would also need to force recalc, post-pasting (as all files are set to
manual calc mode), and then to save only the destination files (those listed
in col D in the instructions table). Source files listed in col A are to be
closed w/o saving. Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Sub to copy n paste as values based on an "instructions" table

Sub copy_data()

Application.CalculateBeforeSave = True
Folder = "E:\ReRun\Visits Detail Tracking\"

RowCount = 2
With ThisWorkbook.Sheets("instructions")
Do While .Range("A" & RowCount) < ""

FromBook = .Range("A" & RowCount).Text
FromRows = .Range("B" & RowCount).Text
FromSheet = .Range("C" & RowCount).Text
ToBook = .Range("D" & RowCount).Text
ToSheet = .Range("E" & RowCount).Text

Workbooks.Open Filename:=Folder & FromBook
Workbooks.Open Filename:=Folder & ToBook

Workbooks(FromBook).Worksheets(FromSheet). _
Rows(FromRows).Copy _
Destination:=Workbooks(ToBook). _
Worksheets(ToSheet).Rows(FromRows)

Workbooks(FromBook).Close SaveChanges:=False
Workbooks(ToBook).Close SaveChanges:=True

RowCount = RowCount + 1
Loop
End With
End Sub

"Max" wrote:

Many thanks, Joel. That worked marvellously.

You can add code to automatically open and close the workbooks.


Sounds like a good idea.

How would your code look like, assuming all the files listed in the
instructions table are located in, say:

E:\ReRun\Visits Detail Tracking

I would also need to force recalc, post-pasting (as all files are set to
manual calc mode), and then to save only the destination files (those listed
in col D in the instructions table). Source files listed in col A are to be
closed w/o saving. Thanks.



  #5   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 9,221
Default Sub to copy n paste as values based on an "instructions" table

Great thanks, Joel !
It works fine, fascinating ...




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to copy a pivot table and "paste special" formats in excel 07 kswan Excel Discussion (Misc queries) 1 October 16th 07 01:27 PM
"list unique" instructions fr xldynamic site doent work Khoshravan Excel Worksheet Functions 4 July 17th 07 08:54 AM
problem with Linking workbooks via "copy" and "paste link" Arkitek Excel Discussion (Misc queries) 0 December 19th 06 10:03 PM
What is Error "Method "Paste" of object "_Worksheet" failed? vat Excel Programming 7 February 17th 06 08:05 PM
Complex if test program possible? If "value" "value", paste "value" in another cell? jseabold Excel Discussion (Misc queries) 1 January 30th 06 10:01 PM


All times are GMT +1. The time now is 05:28 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"