Consolidate Numerous Files

davidhall80

Well-known Member
Joined
Jul 8, 2006
Messages
663
I have a list of paths in column A (about 125). I need to open each one of these files and unhide a tab called Load, copy Range A1:G125, and paste all of this information onto one Tab. I also need to close the workbook I copied from and not save changes. I need to consolidate all of this information in one tab. When copying into the consolidated tab, the new information must be copied under the previous files information. Thanks in advance guys.
Book2
ABCD
1:\Plan-Analysis\2009Plan\Todays\MidAtlanticDistrict\TODYBaltimoreMD.xls
2:\Plan-Analysis\2009Plan\Todays\MidAtlanticDistrict\TODYWashingtonDC.xls
3:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYIndianapolisIN.xls
4:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYMonsantoMO.xls
5:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYClaytonMO.xls
6:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYColumbusOH.xls
7:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYIndianapolisNIN.xls
8:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYIndyPermIN.xls
9:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYCincinnatiDowntownOH.xls
10:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYUSBancorpMO.xls
11:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYUSBancorpOH.xls
12:\Plan-Analysis\2009Plan\Todays\MidAtlanticDistrict\TODYWarwickRI.xls
13:\Plan-Analysis\2009Plan\Todays\MidAtlanticDistrict\TODYPittsburghPA.xls
14:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYEastLouisvilleKY.xls
15:\Plan-Analysis\2009Plan\Todays\MidwestDistrict\TODYLouisvilleDowntownKY.xls
Sheet2
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
You will need to add the drive letter to the file name eg.
Code:
FromFileName = "C" & ListSheet.Cells(FromRow, "A").Value
Code:
'=============================================================================
'- GET DATA FROM FILES LISTED IN A WORKSHEET (column A)
'- Data from Worksheet called "Load" range A1:G125 in each workbook
'- List contains path & file name
'- Brian Baulsom September 2008
'=============================================================================
Sub GET_DATA_FROM_FILE_LIST()
    Dim ListSheet As Worksheet  ' worksheet with list
    Dim FromRow As Long         ' Item row in list
    Dim LastRow As Long         ' last row of list
    Dim ToSheet As Worksheet    ' worksheet called "Consolidation"
    Dim ToRow As Long           ' target row in consolidation
    Dim FromFileName As String  ' source workbook name
    Dim FromBook As Workbook    ' source file
    Dim FromSheet As Worksheet  ' source worksheets all called "Load"
    '-------------------------------------------------------------------------
    '- initialise variables
    Set ListSheet = Worksheets("MyList")
    LastRow = ListSheet.Range("A65536").End(xlUp).Row
    Set ToSheet = Worksheets("Consolidation")
    '-------------------------------------------------------------------------
    '- LOOP THROUGH THE LIST & GET WORKBOOKS
    For FromRow = 1 To LastRow
        '- source file name
        FromFileName = ListSheet.Cells(FromRow, "A").Value
        '----------------------------------------------------------------------
        '- show progress in status bar
        Application.StatusBar = FromRow & "\" & LastRow & " -> " & FromFileName
        '----------------------------------------------------------------------
        '- open workbook
        Set FromBook = Workbooks.Open(FromFileName)
        Set FromSheet = FromBook.Worksheets("Load")
        '---------------------------------------------------------------------
        '- Get ToRow
        ToRow = ToSheet.Range("A65536").End(xlUp).Row + 1
        '---------------------------------------------------------------------
        '- copy/paste data
        FromSheet.Range("A1:G125").Copy Destination:=ToSheet.Cells(ToRow, "A")
        '---------------------------------------------------------------------
        '- close source workbook
        FromBook.Close
        '---------------------------------------------------------------------
    Next
    '-------------------------------------------------------------------------
    MsgBox ("Done")
    Application.StatusBar = False
End Sub
'=============================================================================
 
Upvote 0
how to you adjust this for rtf files? I'm not going to have cells to start and finish at.

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
Members
448,968
Latest member
Ajax40

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top