+ Reply to Thread
Results 1 to 7 of 7

General Question about Collating hundreds of files

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    General Question about Collating hundreds of files

    Hi,
    I have a friend who has hundreds of files in one folder. They each have the exact same header files (first row). Is there an easy script that can combine all her files together into one? For example:
    Folder = Monkey
    File = Monkey1, Monkey2, Monkey3, etc...
    First row is the same for each file and needs to be retained at the top of the collated file.
    # of rows with data vary within each file
    She wants to add an extra column at the very end that has the file name of the original file, so that column Z would say either Monkey1, Monkey2, or Monkey3, etc...

    She has been waiting on someone to help her with this for the better part of a year. But I imagine it is something she could manage on her own, or I could help walk her through, if one of you brilliant people wants to help. It's more endangered monkey conservation work.

    Thank you!

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,065

    Re: General Question about Collating hundreds of files

    Are the files all Excel files (.xsl/.xlsm)? Generated from the same version of Excel?
    Do any of the files contain macros (.xlsm)?
    How many worksheets are in each file?
    Does each file have the same number of worksheets?
    Does each worksheet in a file have the same number of columns? if so, how many?
    Does any file contain more than 25 columns (if they do then youre going to overwite column Z data with the filename as youve suggested).
    Last edited by Special-K; 02-14-2017 at 12:32 PM.
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: General Question about Collating hundreds of files

    Are the files all Excel files (.xsl/.xlsm)? Generated from the same version of Excel? yes
    Do any of the files contain macros (.xlsm)?yes, all .xlsb
    Does each file have the same number of columns? if so, how many? yes, 27
    Does any file contain more than 25 columns (if they do then youre going to overwite column Z data with the filename as youve suggested). I just pulled "Z" as an example but was pretty close! Looks like AB would need to be the file ID column.

  4. #4
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,065

    Re: General Question about Collating hundreds of files

    Does each file have the same number of worksheets?
    Are there any formulas in the workboosk or is it all raw data?

    If you're merging the data, what's going to happen to the macros in the .xlsb files?
    Do they need to be copied into the merged file? Would they still work in the merged file or need to be changed?
    Last edited by Special-K; 02-15-2017 at 06:28 AM.

  5. #5
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,065

    Re: General Question about Collating hundreds of files

    Ok here's a start...

    1. Backup your data first.
    2. Create a file called Merge and insert this piece of VBA, save it as Merge.xlsm

    Sub GetSheets()
    Pth = "D:\!WORK\Install 2\"
    j = 2
    FlNm = Dir(Pth & "Monkey*.xlsb")
        Do While FlNm <> ""
        Workbooks.Open Filename:=Pth & FlNm, ReadOnly:=True
        lastrow = ActiveWorkbook.Worksheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row
        For i = 2 To lastrow
        lastcell = ActiveWorkbook.Worksheets("Sheet1").Cells(i, Columns.Count).End(xlToLeft).Column
        For k = 1 To lastcell
        l = ActiveWorkbook.Worksheets("Sheet1").Cells(i, k)
        Application.Workbooks("Merge.xlsm").Worksheets("Sheet1").Cells(j, k) = l
        Next k
        Application.Workbooks("Merge.xlsm").Worksheets("Sheet1").Cells(j, 28) = FlNm
        j = j + 1
        Next i
        Workbooks(FlNm).Close
        FlNm = Dir()
      Loop
    End Sub
    Change the pathname (Pth) to where your Monkey folders are.

    3) Insert a manual heading in row 1 for the 27 column names. Data will be copied from each workbook into the Merg.xlsm file from row 2 onwards.


    This assumes the following:

    All the Monkey*.xlsb files will have one worksheet called "Sheet1". If this is not the case then you'll need to change "Sheet1" in ActiveWorkBook to whatever the sheet is called in each Monkey file (This is assuming the same sheet name has been used in ALL Monkey files).

    Again, am not sure what's gonna happen to your macros in the original sheets.
    Also this purely copies the data so if there are any formulas you may end up with errors, but obviously I dont know what the data looks like or what formulas are being used.

    Hope this helps.
    Last edited by Special-K; 02-15-2017 at 09:21 AM.

  6. #6
    Forum Contributor
    Join Date
    07-31-2014
    Location
    Texas
    MS-Off Ver
    Mac 2011 Version 14.5.4
    Posts
    114

    Re: General Question about Collating hundreds of files

    Thank you! Let me have her try this. She says that she does not need the macros anymore, just the raw data.
    Fingers crossed! I'll check back in.

  7. #7
    Registered User
    Join Date
    10-04-2017
    Location
    Rochester, United States
    MS-Off Ver
    2010
    Posts
    1

    Re: General Question about Collating hundreds of files

    Hi everyone, I'm the person mermaidNiki was trying to help...I've been trying to work with the code you so kindly provided, but I keep getting an error starting at this line:

    Application.Workbooks("Merge.xlsm").Worksheets("EF").Cells(j, k) = l
    the error says "runtime error 9 script out of range"

    I should note that I have two sets of files to merge (separately), one has 23 columns, the other 7. Though if I understood the code correctly, that should not matter since the program is counting?

    I am happy to send examples of the files if that helps (I've been just using a set of 4 to try to debug this)

    I'm very new to macros so all help is appreciated, thank you!

    Lisa

+ 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. When running hundreds of VBS files at once, only about 50 or so succeed each time
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-17-2015, 05:33 AM
  2. Urget Help - in collating data from different excel files
    By Shruthi_2013 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-08-2013, 04:22 AM
  3. [SOLVED] how to combine hundreds of files into one
    By margosa in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-08-2013, 01:07 PM
  4. [SOLVED] Help with Exporting & Collating Data (newby question)
    By damien102 in forum Excel General
    Replies: 7
    Last Post: 07-26-2012, 09:11 PM
  5. Hundreds of Excel files to work with....
    By CAndrade in forum Excel General
    Replies: 3
    Last Post: 03-18-2009, 11:34 AM
  6. Print file names on all printed excel and word files (hundreds, thousands)
    By forensics in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-05-2009, 01:44 PM
  7. Multiple excel files and collating specific cell info
    By Ska in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-20-2007, 04:48 AM

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