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
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