Results 1 to 4 of 4

Extract data from Multiple excel files

Threaded View

  1. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Extract data from Multiple excel files

    I made a tiny change to your SHEET1 layout. This macro will collect the data as described from your defined folder path (fPATH). Be sure to edit the path in the macro.
    Option Explicit
    
    Sub CollectData()
    Dim wbData As Workbook, ws2 As Worksheet, ws3 As Worksheet, wsDEST As Worksheet
    Dim NR As Long, fPATH As String, fNAME As String
    
    Set wsDEST = ThisWorkbook.Sheets("Sheet1")                  'sheet to build results
    NR = wsDEST.Range("C" & Rows.Count).End(xlUp).Row + 1       'next empty row
    
    fPATH = "C:\TEMP\XXvsYY\"       'path to data files, remember the final \ in this string
    fNAME = Dir(fPATH & "*.xlsx")   'get first filename
    
    Do While Len(fNAME) > 0
        Set wbData = Workbooks.Open(fPATH & fNAME)              'open the found file
        wsDEST.Range("A" & NR).Value = fNAME                    'filename in col A, timestamp in col B
        wsDEST.Range("B" & NR).Value = Format(FileDateTime(wbData.FullName), "m/d/yy h:mm am/pm")
        With wsDEST.Range("C" & NR).Resize(, 4)                 'collect info from sheet2
            .Formula = "=COUNTIF('[" & fNAME & "]" & wbData.Sheets(2).Name & "'!C6, R2C)"
            .Value = .Value
        End With
        With wsDEST.Range("G" & NR).Resize(, 4)                 'collect info from sheet3
            .Formula = "=COUNTIF('[" & fNAME & "]" & wbData.Sheets(3).Name & "'!C6, R2C)"
            .Value = .Value
        End With
    
        wbData.Close False          'close the data file
        NR = NR + 1                 'next empty row
        fNAME = Dir                 'get next filename
    Loop
    
    End Sub
    Attached Files Attached Files
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Extract Data from Multiple Closed Excel Files
    By Gittelman in forum Excel General
    Replies: 2
    Last Post: 07-29-2014, 12:09 AM
  2. Replies: 0
    Last Post: 07-28-2014, 10:19 PM
  3. Extract Data from multiple excel files based on a Enquirer ID
    By pmyk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-28-2013, 01:40 AM
  4. Extract Data From Multiple Excel Files -> One File
    By ozzabozza in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-16-2013, 10:20 AM
  5. Load multiple excel files into an excel sheet and extract data
    By Martijn79 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-03-2013, 06:08 PM
  6. [SOLVED] Extract Data From Multiple Excel Files -> One File
    By Michael via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-24-2012, 01:02 PM
  7. Replies: 0
    Last Post: 06-17-2008, 12:39 PM

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