+ Reply to Thread
Results 1 to 5 of 5

Consolidating multiple files into one excel file with multiple tabs

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-19-2009
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    147

    Consolidating multiple files into one excel file with multiple tabs

    Hi all,

    I would really appreciate it if someone could give me advice on if the following is possible.

    I will be saving files into one folder in the following manner:

    Project ABC June report (Sheets = mikes summary, mikes budget, mikes risks)
    Project DEF June report (Sheets = john summary, john budget, john risks)
    Project XYZ June report (Sheets = jane summary, jane budget, jane risks)

    The number of files may vary month by month depending on projects on the go.

    I would like to create a master file that has a macro in it that pulls the first sheet (and only the first sheet) from each of the other workbooks and keeps them in individual sheets in the master document.

    So the master document would look like

    Master document (Sheets = Mikes summary, Johns summary, janes summary etc)

    Is this do-able?

    Thanks in advance for looking at it.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Consolidating multiple files into one excel file with multiple tabs

    Whats the range that should be copied from each sheet?

    Will the master file be a blank file to start with?

    When you re-run the macro (maybe the following week or so), do you want the contents of the master file to be cleared and fresh data included?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    08-19-2009
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    147

    Re: Consolidating multiple files into one excel file with multiple tabs

    Hi Arlette,

    Thanks for replying. The range would be the entire of the first sheet (actual data is A1:H56 but their is a potential this could change)

    So long as the master file ended up with a copy of each of the different projects summary sheets then i dont mind if it is blank to begin with or has data in

    When i re run the macro i would want the contents to be cleared and fresh data put in

    Dhanyavadagalu

  4. #4
    Forum Contributor
    Join Date
    08-19-2009
    Location
    uk
    MS-Off Ver
    Excel 2010
    Posts
    147

    Re: Consolidating multiple files into one excel file with multiple tabs

    Hello all. I posted this on here a couple of days ago but it didn't seem to get much interest. Anyone able to help me out?

    Many thanks,

    Chemist

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Consolidating multiple files into one excel file with multiple tabs

    Try this code
    Option Explicit
    
    Sub cons_data()
    
    Dim Master As Workbook
    Dim sourceBook As Workbook
    Dim sourceData As Worksheet
    Dim CurrentFileName As String
    Dim myPath As String
    Dim i As Long
    Dim sname As String
    
    'The folder containing the files to be recap'd
    myPath = "D:\Test"
    
    'Finds the name of the first file of type .xls in the current directory
    CurrentFileName = Dir(myPath & "\*.xlsx")
    
    'Create a workbook for the recap report
    Set Master = ThisWorkbook
    
    For i = 1 To Master.Worksheets.Count
        Master.Worksheets(i).Cells.ClearContents
    Next i
    
    Do
        Workbooks.Open (myPath & "\" & CurrentFileName)
        Set sourceBook = Workbooks(CurrentFileName)
                
            With sourceBook
                For i = 1 To .Worksheets.Count
                    If .Worksheets(i).Name Like "* summary" Then
                        sname = .Worksheets(i).Name
                        Master.Activate
                        If Not Evaluate("ISREF('" & sname & "'!A1)") Then
                            Master.Worksheets.Add(After:=Master.Worksheets(Worksheets.Count)).Name = sname
                        End If
                        .Worksheets(sname).Cells.Copy Master.Worksheets(sname).Range("A1")
                        Exit For
                    End If
                Next i
            End With
           
        sourceBook.Close
      
    'Calling DIR w/o argument finds the next .xlsx file within the current directory.
    CurrentFileName = Dir()
    Loop While CurrentFileName <> ""
    
    End Sub
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose Tools | Macro | Macros
    Select a macro in the list, and click the Run button

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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