Consolidating multiple separate workbooks into one "Consolidated Workbook"

Adnandos

New member
Joined
Jun 12, 2018
Messages
25
Reaction score
0
Points
0
Excel Version(s)
365
Hi all -not sure exactly where to post this.

I have 20 workbooks that is prepared by 20 different users monthly.

In each workbook there are 5 worksheet tabs, each "clean" workbook is identical in every sense, layout, structure etc.

Meaning worksheet 3 in workbook 1 is identical to worksheet 3 in workbook 2 etc. The users capture data into each worksheet into the respective columns.

At the end of each month I literally open a "clean consolidated" workbook, and begin opening each worksheet in each completed workbook and manually copy it into the consolidated workbook.

There must be a faster way of doing this (macro, vba, something else?) if the relevant workbooks are all stored in the same folder?

If there is, please share how this could be done.

Would really appreciate any assistance, and like I said, not sure where this should have been posted.
 
Yes you need to use Get data in Excel and import a folder containing all 20 workbooks and then append each 20 sheet 1's, sheet 2's...

Consider sending 3 workbooks with fictitious data 3-5 lines in each tab of each workbook and I will do it for you then all you need do is connect it to your real data and refresh it. Need to see the exact structure in case any kinks need to be handled.

Knock 'em dead Sailor!
 
.
Paste this into a Routine Module :

Code:
Option Explicit


 '32-bit API declarations
Declare Function SHGetPathFromIDList Lib "shell32.dll" _
Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal _
pszpath As String) As Long
 
Declare Function SHBrowseForFolder Lib "shell32.dll" _
Alias "SHBrowseForFolderA" (lpBrowseInfo As BrowseInfo) _
As Long
 
Public Type BrowseInfo
    hOwner As Long
    pIDLRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type
 
Function GetDirectory(Optional msg) As String
    On Error Resume Next
    Dim bInfo As BrowseInfo
    Dim path As String
    Dim r As Long, x As Long, pos As Integer
     
     'Root folder = Desktop
    bInfo.pIDLRoot = 0&
     
     'Title in the dialog
    If IsMissing(msg) Then
        bInfo.lpszTitle = "Please select the folder of the excel files to copy."
    Else
        bInfo.lpszTitle = msg
    End If
     
     'Type of directory to return
    bInfo.ulFlags = &H1
     
     'Display the dialog
    x = SHBrowseForFolder(bInfo)
     
     'Parse the result
    path = Space$(512)
    r = SHGetPathFromIDList(ByVal x, ByVal path)
    If r Then
        pos = InStr(path, Chr$(0))
        GetDirectory = Left(path, pos - 1)
    Else
        GetDirectory = ""
    End If
End Function
 
Sub CombineFiles()
    Dim path            As String
    Dim FileName        As String
    Dim LastCell        As Range
    Dim Wkb             As Workbook
    Dim WS              As Worksheet
    Dim ThisWB          As String
    Dim pasteSht        As Worksheet
    
    ThisWB = ThisWorkbook.Name
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    path = GetDirectory
    FileName = Dir(path & "\*.xls*", vbNormal)
    Set pasteSht = Worksheets("Sheet1")
    
    Do Until FileName = ""
        If FileName <> ThisWB Then
            Set Wkb = Workbooks.Open(FileName:=path & "\" & FileName)
            For Each WS In Wkb.Worksheets
                Set LastCell = WS.Cells.SpecialCells(xlCellTypeLastCell)
                If LastCell.Value = "" And LastCell.Address = Range("$A$1").Address Then
                Else
                    WS.Copy After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
                    
                End If
            Next WS
            Wkb.Close False
        End If
        FileName = Dir()
    Loop
    Application.EnableEvents = True
    Application.ScreenUpdating = True
     
    Set Wkb = Nothing
    Set LastCell = Nothing
End Sub

See attached
 

Attachments

  • Copy All Books.xlsm
    22.8 KB · Views: 30
Apologies for the late response, this ended up being the type of solution that worked. Get data, append and working with queries made my life much easier!
 
Back
Top