Hello All
I am trying to write one macro to run on 3 files inside a folder. Code is written but it copies data and overwrites in the same range for next files. I want data from source file to go in target file range G5:G32 for 1 st file/E5:E32 for second file and F5:F32 for third file. Each source file has two sheets to bring data from. Also target file has two sheets for the data to go into. Here is the code so far. Trying offset but no success!
Sub LoopThroughFolder()
Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
Dim Rws As Long, Rng As Range
Set Wb = ThisWorkbook
MyDir = "C:\MacrosTest\Folder Testing"
MyFile = Dir(MyDir & "*.xlsx")
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
Do While MyFile <> ""
Workbooks.Open (MyFile)
With Worksheets(1)
Set Rng = Range(.Cells(5, "N"), .Cells(32, "N"))
Rng.Copy Wb.Worksheets("BATTERY10").Cells(5, "G")
End With
With Worksheets(2)
Set Rng = Range(.Cells(5, "N"), .Cells(34, "N"))
Rng.Copy Wb.Worksheets("UNIT 700").Cells(5, "G")
ActiveWorkbook.Close True
End With
MyFile = Dir()
Loop
End Sub
I am trying to write one macro to run on 3 files inside a folder. Code is written but it copies data and overwrites in the same range for next files. I want data from source file to go in target file range G5:G32 for 1 st file/E5:E32 for second file and F5:F32 for third file. Each source file has two sheets to bring data from. Also target file has two sheets for the data to go into. Here is the code so far. Trying offset but no success!
Sub LoopThroughFolder()
Dim MyFile As String, Str As String, MyDir As String, Wb As Workbook
Dim Rws As Long, Rng As Range
Set Wb = ThisWorkbook
MyDir = "C:\MacrosTest\Folder Testing"
MyFile = Dir(MyDir & "*.xlsx")
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
Do While MyFile <> ""
Workbooks.Open (MyFile)
With Worksheets(1)
Set Rng = Range(.Cells(5, "N"), .Cells(32, "N"))
Rng.Copy Wb.Worksheets("BATTERY10").Cells(5, "G")
End With
With Worksheets(2)
Set Rng = Range(.Cells(5, "N"), .Cells(34, "N"))
Rng.Copy Wb.Worksheets("UNIT 700").Cells(5, "G")
ActiveWorkbook.Close True
End With
MyFile = Dir()
Loop
End Sub