Results 1 to 7 of 7

Connect data from hundreds of closed workbooks to one workbook

Threaded View

  1. #6
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Connect data from hundreds of closed workbooks to one workbook

    You may want to try this macro that will open every files and extract the sum of the shop sales from every tabs it contains.
    Look at the comments in the code for some specifics issues about this code.
    Public Sub Lookup_Values()
    'in order for this macro to work you must follow those rules:
    '1. Files names must be structured as YYYY MM DD.xlsx (ex. 2014 05 15.xlsx)
    'Months and days lower than 10 must have a 0 before the digit
    '2. Put this workbook in the same folder as all the other files.
    '3. The year is calculated from the tabs name in the code below
    '4. The tabs name must be written as a data in the format MMM YY would be in your regional settings.
    '   (ex. in english February 2014 would be Feb 14 but in french it would have been Fév 14)
    '   I don't know what it will be in protuguese but it has to be that way because
    '   I use the tab name in the month function to find the month and year of this tab.
    Dim Sh_Temp As Worksheet, File_Name As String, C_ell As Range, Y_ear As String
    Dim M_onth As String, D_ay As String, WB As Workbook, Sh_A As Worksheet
    Dim F_ound As Range, S_hop As Range
    '
    Application.ScreenUpdating = False
    '
    For Each Sh_Temp In ActiveWorkbook.Worksheets
       Sh_Temp.Activate
       '
       For Each C_ell In Range("B2", Cells(2, Columns.Count).End(xlToLeft))
          'This section is creating the file name based on the tab's name and the number in row 2 of each file.
          Y_ear = Year(Sh_Temp.Name)
          If Month(Sh_Temp.Name) < 10 Then
             M_onth = "0" & Month(Sh_Temp.Name)
          Else
             M_onth = Month(Sh_Temp.Name)
          End If
          If C_ell < 10 Then
             D_ay = "0" & C_ell
          Else
             D_ay = C_ell
          End If
          '
          File_Name = Y_ear & " " & M_onth & " " & D_ay & ".xlsx"
          '
          If Dir(ActiveWorkbook.Path & "\" & File_Name) <> "" Then
             'This line open the specific file for this month and day
             Workbooks.Open Filename:=ActiveWorkbook.Path & "\" & File_Name
             '
             Set WB = ActiveWorkbook
             Sh_Temp.Activate
             '
             For Each S_hop In Range("A3", Cells(Rows.Count, 1).End(xlUp))
                'This line erases the original content of the target cell
                'If you don't want this to append, DELETE IT or COMMENT IT
                'In this case the values of the files will be added to existing amount in cell
                Cells(S_hop.Row, C_ell.Column) = 0
                'This section looks into every sheet in the file and adds the shop's sales
                For Each Sh_A In WB.Worksheets
                   Set F_ound = Sh_A.Columns(1).Find(What:=S_hop, Lookat:=xlWhole)
                   If Not F_ound Is Nothing Then
                      Cells(S_hop.Row, C_ell.Column) = Cells(S_hop.Row, C_ell.Column) + F_ound.Offset(0, 1)
                   End If
                Next
             Next
             Workbooks(File_Name).Close False
          End If
          '
    N_ext:
       Next
    Next
    Application.ScreenUpdating = True
    End Sub
    Hope this will help.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. vba vlookup updates current data's from closed workbook undefined name of workbooks
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-27-2013, 06:53 AM
  2. Import data from several closed workbooks to a single sheet in an open workbook
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-04-2013, 06:35 AM
  3. Extract data from closed workbooks and copy into new workbook
    By philaugust2004 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-15-2013, 07:45 AM
  4. Copy Sheet from one Workbook to Multiple Closed Workbooks
    By sflexi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2013, 10:01 AM
  5. Copy Data to One Workbook From Multiple Closed Workbooks
    By Ben4481 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-04-2010, 08:02 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