Read all Excel from a specific folder and paste them in 1 Excel

Vagelisr

New Member
Joined
Sep 22, 2016
Messages
28
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hi to all.
I want to read all excel files from a specific folder and paste them in 1.

The point is
After the first excel file i want from the rest to make a range excludind the headers. (the first 3 lines)

I try this one where work fine for the first one but I'm unable to create a range for the second one and i need your help.
The range for the second excel is with red color.

Thanks and regards

Code:
Public Folder As String
Public FirstExcel As Boolean
Public TabName As String
Public CellName As String
Public First_Time As Boolean

Sub Merge()
    Dim arg As String
    Dim LastMainRow As Integer
    Dim FirstLine As Integer
    FirstLine = Worksheets("Parm").Cells(2, 2).Value + 1
    Folder = BrowseForFolder & "\"
    If Folder <> "" Then
        myExtension = "*.xls"
        myfiles = Dir(Folder & myExtension)
        Row = 1
        Worksheets("DataAll").Activate
        ActiveSheet.Cells.Clear
        FirstExcel = False
        Do While myfiles <> ""
        'OK---------------------------------------------------------------------------------
            MsgBox Folder & myfiles
            'Open the Specific Excell
            Workbooks.Open (Folder & myfiles)
            ActiveWorkbook.RunAutoMacros xlAutoOpen
            fname = ActiveWorkbook.Name
            
            'Copy the Specific Excell
            Workbooks(myfiles).Activate
            Worksheets("Data").Activate
            If FirstExcel = False Then
                ActiveSheet.Cells.Select
                Selection.Copy
                FirstExcel = True
            Else
                lRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row 'Last Row
                lCol = ActiveSheet.Cells(2, Columns.Count).End(xlToLeft).Column 'Last Column

                
               [COLOR=#ff0000] Range(Cells("1", FirstLine), Cells(lCol, lRow)).Select[/COLOR]
                Selection.Copy
            End If
             
            'Paste the Specific Excell to Data
            Workbooks("File_Merge_Split.xls").Activate
            Worksheets("DataAll").Activate
            LastMainRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row 'Last Row
            ActiveSheet.Cells(1, LastMainRow).Select
            ActiveSheet.Paste
            
            'Close Copy File
            Application.DisplayAlerts = False
            Workbooks(myfiles).Close SaveChanges:=False
            Application.DisplayAlerts = True
            
            myfiles = Dir
        Loop
    End If
End Sub

Function BrowseForFolder(Optional OpenAt As Variant) As Variant
    Dim ShellApp As Object
    Set ShellApp = CreateObject("Shell.Application"). _
    BrowseForFolder(0, "Please select a folder", 0, OpenAt)
    On Error Resume Next
    BrowseForFolder = ShellApp.self.Path
    On Error GoTo 0
    Set ShellApp = Nothing
    Select Case Mid(BrowseForFolder, 2, 1)
    Case Is = ":"
        If Left(BrowseForFolder, 1) = ":" Then GoTo Invalid
    Case Is = "\"
        If Not Left(BrowseForFolder, 1) = "\" Then GoTo Invalid
    Case Else
        GoTo Invalid
    End Select
    Exit Function
Invalid:
    BrowseForFolder = False
End Function
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top