+ Reply to Thread
Results 1 to 7 of 7

import data from multiple closed files to master file

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-12-2015
    Location
    Okinawa, Japan
    MS-Off Ver
    2013
    Posts
    178

    import data from multiple closed files to master file

    Greetings all,

    I have been searching and have not quite found an answer for my project. I want to import data from multiple closed excel files into one master file that is open.
    1. All files (source and target) will reside in one folder.
    2. I would like to import from all files regardless of their name if that is possible.
    3. I want to import data from cells A1:C40.
    4. I want to import data to one sheet that will add the subsequent data below the previous.

    Your help is greatly appreciated.

    Ken

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: import data from multiple closed files to master file

    You could try this.
    Sub Maybe_Like_So()
        Dim wb As String
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
        wb = Dir(ThisWorkbook.Path & "\*")
        Do Until wb = ""
            If wb <> ThisWorkbook.Name Then
                Workbooks.Open ThisWorkbook.Path & "\" & wb
                With Workbooks(wb).Sheets("Sheet1")
                    .Range("A1:C40).Copy ThisWorkbook.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Offset(1)
                End With
                Application.CutCopyMode = False
                Workbooks(wb).Close False
            End If
            wb = Dir
        Loop
        
        With Application
            .Calculation = xlAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    
    End Sub
    Or maybe so

    Sub Maybe_Like_So_Values_Only()
        Dim wb As String
    
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .ScreenUpdating = False
        End With
    
        wb = Dir(ThisWorkbook.Path & "\*")
        Do Until wb = ""
            If wb <> ThisWorkbook.Name Then
                Workbooks.Open ThisWorkbook.Path & "\" & wb
                    ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(40, 3).Value = Workbooks(wb).Sheets("Sheet1").Range("A1:C40").Value
                Workbooks(wb).Close False
            End If
            wb = Dir
        Loop
        
        With Application
            .Calculation = xlAutomatic
            .EnableEvents = True
            .ScreenUpdating = True
        End With
        
    End Sub
    Last edited by jolivanes; 02-22-2017 at 02:47 AM. Reason: 2nd option

  3. #3
    Forum Contributor
    Join Date
    09-12-2015
    Location
    Okinawa, Japan
    MS-Off Ver
    2013
    Posts
    178

    Re: import data from multiple closed files to master file

    Thank you for your post. I used the second code and it worked great...thank you so much.

  4. #4
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: import data from multiple closed files to master file

    Another possibility..

    * Build a 2d array from the source data from each workbook in the folder and dump it at the end..


    bah.. can't post the code as Succuri firewall thingo is blocking it.. see attached file...

    Change strpath as needed..
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    09-12-2015
    Location
    Okinawa, Japan
    MS-Off Ver
    2013
    Posts
    178

    Re: import data from multiple closed files to master file

    Thank you for your post.

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: import data from multiple closed files to master file

    majime01
    ブックは閉じたままで...
    Sub test()
        Dim fn As String, wbName As String
        Const myRng As String = "A1:C40", myWs As String = "Sheet1"  '<- 適時変更
        fn = Dir(ThisWorkbook.Path & "\*.xls")
        Do While fn <> ""
            If fn <> ThisWorkbook.Name Then
                With ThisWorkbook.Sheets(1).Range("a" & Rows.Count).End(xlUp)(2).Range(myRng)
                    .Formula = "='[" & Mid$(fn, InStrRev(fn, "/") + 1) & "]" & myWs & "'!" & Split(myRng, ":")(0)
                End With
            End If
            fn = Dir
        Loop
        With ThisWorkbook.Sheets(1).Range(myRng).EntireColumn
            .Value = .Value
        End With
    End Sub

  7. #7
    Forum Contributor
    Join Date
    09-12-2015
    Location
    Okinawa, Japan
    MS-Off Ver
    2013
    Posts
    178

    Re: import data from multiple closed files to master file

    Arigato tomadachi

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Combine data from multiple files into a master file using VBA
    By bdrod in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-18-2016, 06:00 PM
  2. Help with data import from files to master file
    By RoyLittle0 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-04-2013, 03:46 PM
  3. Vba macro help to pull data from multiple closed files to master file !!!
    By johnodys in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2013, 07:44 AM
  4. [SOLVED] Import data from excel files to append master file
    By kdawgpl9 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-19-2013, 04:32 PM
  5. Consolidate Data from Multiple Files (Different File Names) into a Master File
    By dspraveen_23 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-08-2012, 12:59 PM
  6. [SOLVED] A macro to Import data from many unique files into one master file
    By Researcher007 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-16-2012, 12:48 AM
  7. Searching other files to import to specified cells in a master file
    By cultavix in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-17-2008, 09:41 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1