Your original question and your sample workbooks do not match.
Here is the code that reflects on the sample workbook you have provided.
Your destination workbook is the workbook with the code and will be saved as a macro enabled workbook(.xlsm)
Change the folder address in the code.
There are two worksheets in the destination workbook. One named Columns and one named Rows.
Sub LoopThroughFolder()
Dim MyFile As String, Str As String, MyDir As String, wb As Workbook
Dim rws As Long, rng1 As Range, rng2 As Range
Dim sh1 As Worksheet, sh2 As Worksheet
Dim Lstcl As Long, Lstrws As Long, cl As Long
Set wb = ThisWorkbook
Set sh1 = wb.Sheets("Columns")
Set sh2 = wb.Sheets("Rows")
'change the address to suite
MyDir = "C:\Users\Dave\SkyDrive\Documents\New folder" & "\"
MyFile = Dir(MyDir & "*.xlsx") 'change file extension
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
Do While MyFile <> ""
Workbooks.Open (MyFile)
With Worksheets(1)
rws = .Cells(Rows.Count, "G").End(xlUp).Row
cl = .Cells(6, .Columns.Count).End(xlToLeft).Column
Set rng1 = .Range(.Cells(5, 7), .Cells(rws, 7))
Set rng2 = .Range(.Cells(6, 9), .Cells(6, cl))
With sh1
If .Cells(1, 1) = "" Then
Lstcl = 1
Else
Lstcl = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
End If
End With
With sh2
If .Cells(1, 1) = "" Then
Lstrws = 1
Else
Lstrws = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End If
End With
rng1.Copy
sh1.Cells(1, Lstcl).PasteSpecial xlPasteValues
rng2.Copy
sh2.Cells(Lstrws, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
End With
ActiveWorkbook.Close True
MyFile = Dir()
Loop
End Sub
Display More