Results 1 to 5 of 5

Combine files in VBA

Threaded View

  1. #1
    Registered User
    Join Date
    03-17-2014
    Location
    Hong Kong
    MS-Off Ver
    Excel 2010
    Posts
    4

    Combine files in VBA

    I read some threads, and write down this code. The purpose is for combining excel files into one.
    For example, I have 10 data files. All of them are in the same format with 2 sheets. I want to use the VBA code to combine them into one excel file.
    After testing, lots of data are missing. I use F8 to check it step by step, and found out that the new files data will replace the old one, etc.

    What should this code be amended for my purpose?
    If FileNum > 0 Then
            Dim Arr
            ReDim Arr(1 To FileNum, 1 To 2)
            For FileNum = LBound(MyFiles) To UBound(MyFiles)
                Set mybook = Workbooks.Open(FilePath & MyFiles(FileNum))
                Sheets("CLASS A").Activate
                RowCount = Range("A1").End(xlDown).Row
                Arr(FileNum, 1) = Range(Range("A2"), Range("E2").Offset(RowCount - 1))
            
                Sheets("CLASS B").Activate
                RowCount = Range("A1").End(xlDown).Row
                Arr(FileNum, 2) = Range(Range("A2"), Range("E2").Offset(RowCount - 1))
            
                ActiveWorkbook.Close
                Sheets("CLASS A").Activate
                Range("A2").Resize(UBound(Arr(FileNum, 1), 1), UBound(Arr(FileNum, 1), 2)) = Arr(FileNum, 1)
                Sheets("CLASS B").Activate
                Range("A2").Resize(UBound(Arr(FileNum, 2), 1), UBound(Arr(FileNum, 2), 2)) = Arr(FileNum, 2)
            
            Next FileNum
                        
        End If

    Thank you!!
    Last edited by Andy910104; 03-18-2014 at 12:11 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [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
  2. Combine all Files into 1
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2009, 12:56 PM
  3. Combine files
    By TinaK819 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-30-2009, 03:07 PM
  4. Combine csv files
    By RevJeff in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2006, 04:55 PM
  5. [SOLVED] combine two files
    By Charles in forum Excel General
    Replies: 1
    Last Post: 08-09-2005, 05:05 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