+ Reply to Thread
Results 1 to 3 of 3

Combine Data from Multiple Worksheets and Multiple Files into one master table in workbook

  1. #1
    Registered User
    Join Date
    06-03-2014
    Posts
    2

    Combine Data from Multiple Worksheets and Multiple Files into one master table in workbook

    I created a template for work for everyone to submit their budgets. The template has 20 tabs named Task 1 - Task 20. The input fields aren't locked, but all other fields are. I will be receiving about 200 files. I want all of the data to go into one tab on one Excel file in a table that collects all of the data. The data in the template is the same in each file, but it is not in table form, so the master table will be different. Is there a macro that can pull all the data or is there a way to reference each cell I need to create the table in VBA? I am happy to provide more information.

    Thank you for your help!

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Combine Data from Multiple Worksheets and Multiple Files into one master table in work

    I put together this macro back in September.

    Please Login or Register  to view this content.
    This will take every file of a certain file extension in a single folder, copy every tab of each of those workbooks to a single excel spreadsheet, and then consolidate each tab into a single tab so you have one huge list. This might get you started in the right direction.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    06-03-2014
    Posts
    2

    Re: Combine Data from Multiple Worksheets and Multiple Files into one master table in work

    Thank you for your response! I'm using the below macro. The only problem is it is not pulling in rows that might be hidden or filtered. Do you know how I can tell this macro to pull in all rows regardless of if it is hidden or filtered?

    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 lastrow As Long
    Dim lrow As Long
    Dim i As Long

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    'The folder containing the files to be recap'd
    myPath = "S:\FY2015\Macro_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
    With Master.Worksheets(i)
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    If lrow > 1 Then .Rows("2:" & lrow).ClearContents
    End With
    Next i

    Do
    Workbooks.Open (myPath & "\" & CurrentFileName)
    Set sourceBook = Workbooks(CurrentFileName)
    For i = 1 To sourceBook.Worksheets.Count
    Set sourceData = sourceBook.Worksheets(i)

    With sourceData
    lastrow = Master.Worksheets(.Name).Range("A" & Rows.Count).End(xlUp).Row
    lrow = .Range("A" & .Rows.Count).End(xlUp).Row
    .Rows("2:" & lrow).Copy Master.Worksheets(.Name).Rows(lastrow + 1)
    End With
    Next i

    sourceBook.Close

    'Calling DIR w/o argument finds the next .xlsx file within the current directory.
    CurrentFileName = Dir()
    Loop While CurrentFileName <> ""

    MsgBox "Done"

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

    End Sub

+ 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 several workbooks containing data in multiple sheets into a master Workbook
    By sunrize9 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-09-2014, 09:10 PM
  2. [SOLVED] Displaying Data from multiple worksheets into a master workbook
    By jackee96 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-17-2013, 05:31 PM
  3. How to automatically combine data from multiple worksheets into a master worksheet
    By BeardedLuminary in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-28-2013, 10:57 AM
  4. Copy/Paste Range of Data from Multiple Workbooks/Worksheets to Master Workbook/Worksheets
    By NumberCruncher311 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 08:21 PM
  5. [SOLVED] Can't create a Master Pivot table from multiple worksheets in the same workbook
    By dwhite30518 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 05-30-2012, 09:41 AM

Tags for this Thread

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