Results 1 to 10 of 15

Thread: Meger multiple file but header not same

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Try

    Code:
    Option Explicit
    
    Sub ConsolidateWorkbooks()
        
        Dim j           As Long
        Dim Fldr        As String
        Dim Fname       As String
        Dim wbkActive   As Workbook
        Dim wbkSource   As Workbook
        Dim Dest        As Range
        
        '// User settings
        Const SourceFileType        As String = "xls*"  'xls,xlsx,xlsb,xlsm
        Const DestinationSheet      As String = "Sheet1"
        Const DestStartCell         As String = "A1"
        Const StartRow              As Long = 2
        '// End
        
        Application.ScreenUpdating = False
        With Application.FileDialog(4)
            .Title = "Select source file folder"
            .AllowMultiSelect = False
            If .Show = -1 Then
                Fldr = .SelectedItems(1)
            Else
                GoTo Xit
            End If
        End With
        
        Set wbkActive = ThisWorkbook
        
        Set Dest = wbkActive.Worksheets(DestinationSheet).Range(DestStartCell)
        
        Fname = Dir(Fldr & "\*." & SourceFileType)
        
        Do While Len(Fname)
            If wbkActive.Name <> Fname Then
                Set wbkSource = Workbooks.Open(Fldr & "\" & Fname)
                With wbkSource.Worksheets(1)
                    j = .Range("a" & .Rows.Count).End(3).Row
                    .Range("a2:as" & j).Copy Dest
                    Set Dest = Dest.Offset(j)
                End With
                wbkSource.Close 0
                Set wbkSource = Nothing
            End If
            Fname = Dir()
        Loop
        
    Xit:
        Application.ScreenUpdating = True
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Merge multiple file but header not same

    Thanks buddy, now it is working....
    Last edited by Admin; 10-25-2012 at 07:50 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    Merge multiple file but header not same

    Hi

    I have run this macro and it is working fine. But there is blank row coming in consolidated sheet after sheet data. For example one workbook data is pasted in consolidated sheet and then one row left blank. Then second workbook data is pasted and then one row blank. There thirty row leave blank because thirty file to consolidate.

    Seondly the formating of sheet is not proper way. Is there any way to consolidate the data as value so that cell size does not change.

    Quote Originally Posted by rocky View Post
    Thanks buddy, now it is working....

Similar Threads

  1. Replies: 1
    Last Post: 06-07-2013, 10:32 AM
  2. Loop Through And Delete Multiple File Types In A Folder
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 03-30-2013, 04:47 PM
  3. Replies: 1
    Last Post: 03-07-2013, 11:42 AM
  4. Consolidate multiple workbooks from a folder into one master file VBA
    By Admin in forum Excel and VBA Tips and Tricks
    Replies: 4
    Last Post: 02-26-2013, 09:00 PM
  5. Sort Data When a Header Is Clicked
    By Rasm in forum Excel Help
    Replies: 9
    Last Post: 08-01-2012, 06:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •