close

I have 3 workbooks, each contains the same 30 tabs, but each workbook
contains different information. There is a main workbook, and two extra with
information that I need to put all together on the main workbook. I am
looking for the easiest way to paste the info from the 2 workbooks into the
main work book without having to do it tab by tab and workbook by workbook.
Anyone have any suggestions?


Hi,
I'm hoping that you know how to use macros, if not, you may find the
link below useful:
( www.mvps.org/dmcritchie/excel/getstarted.htm )

1 Open all three files.
2 Copy the macro below into a module of the VBA project of your main
workbook (in Excel press [ALT F11] (this opens the VB Editor), right
click on the VBA project of your file, Insert-Module).
3 Paste the code below into the resulting sheet that appears.
4 Change the file names in the appostrophes (as commented), change the
ranges as required amp; run the macro by placing the cursor within the
code .
Please note:
* may have word wrapping (the space amp; underscore, ie quot; _quot;) in the wrong
places,
* that the below does not include error handling,
* hasn't been tested for speed or handling of large data sets,
* will over write any data that exists in the destination cells of the
main workbook,
* and most of all, requires all the sheet names to be exactly the same
in each of the 3 workbooks.

Sub CopyThirtyTabs()
Dim CopiedFrom1 As String
Dim CopiedFrom2 As String
Dim MainWorkbook As Workbook
Dim ws As Worksheet
Dim i As Long
Dim DataSheetName() As String

CopiedFrom1 = quot;copiedfrom1.xlsquot; 'change file name as needed
CopiedFrom2 = quot;copiedfrom2.xlsquot; 'change file name as needed
Set MainWorkbook = ThisWorkbook

' Store the sheet names as separate strings
ReDim DataSheetName(1 To 30) 'The # of tabs
For Each ws In MainWorkbook.Worksheets
i = i 1
DataSheetName(i) = ws.Name
Next ws

'Copies selected data from each of the workbooks into the main one for
_
each of the 30 sheets.
For i = 1 To 30

Workbooks(CopiedFrom1).Worksheets(DataSheetName(i) ).Range(quot;a1:b10quot;).Copy
_
MainWorkbook.Worksheets(DataSheetName(i)).Range(quot;a 1:b10quot;)Workbooks(CopiedFrom2).Worksheets(DataSheetName(i) ).Range(quot;a1:b10quot;).Copy
_
MainWorkbook.Worksheets(DataSheetName(i)).Range(quot;c 1:d10quot;)
'Note the different destination range for pasting into on the
second copy.
Next i
MsgBox quot;all done :-)quot;
End Subbtw, Another similar thread may also help you:
excelforum.com/showthread.php...hlight=started

hth
Rob Brockett
NZ
Always learning amp; the best way to learn is to experience...--
broro183
------------------------------------------------------------------------
broro183's Profile: www.excelforum.com/member.php...oamp;userid=30068
View this thread: www.excelforum.com/showthread...hreadid=526139

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()