i'm trying to come up with a code which copies data from last rows of multiple workbooks in a folder and paste into another workbook(Master file). The below mentioned code copies the complete data present in all the workbooks in the folder and paste it into another workbook without any issues:
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:\Users\Jeevesh\Desktop\Dump\New folder\"
MyFile = Dir(MyDir & "*.xls")
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
Do While MyFile <> ""
Workbooks.Open (MyFile)
With Worksheets("Activity Data")
Rws = .Cells(Rows.Count, "B").End(xlUp).Row
Set Rng = Range(.Cells(2, 1), .Cells(Rws, 9))
Rng.Copy Wb.Worksheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Offset(1, -1)
ActiveWorkbook.Close True
End With
Application.DisplayAlerts = 1
MyFile = Dir()
Loop
End Sub
Now i'm not able to make changes to the code which will only copy the last used row from all the workbooks present in the folder and paste it into another workbook.
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:\Users\Jeevesh\Desktop\Dump\New folder\"
MyFile = Dir(MyDir & "*.xls")
ChDir MyDir
Application.ScreenUpdating = 0
Application.DisplayAlerts = 0
Do While MyFile <> ""
Workbooks.Open (MyFile)
With Worksheets("Activity Data")
Rws = .Cells(Rows.Count, "B").End(xlUp).Row
Set Rng = Range(.Cells(2, 1), .Cells(Rws, 9))
Rng.Copy Wb.Worksheets("Sheet1").Cells(Rows.Count, "B").End(xlUp).Offset(1, -1)
ActiveWorkbook.Close True
End With
Application.DisplayAlerts = 1
MyFile = Dir()
Loop
End Sub
Now i'm not able to make changes to the code which will only copy the last used row from all the workbooks present in the folder and paste it into another workbook.