preethi3290
New Member
Hi,
I have a main folder containing 25 sub folders. daily I will add one new excel sheet to each sub folder. I want to copy part of the Excel sheet data from 25 excel sheets which are in 25 sub folders and paste in a new master excel sheet.
Then I have to upload the master excel sheet in MS Access.
I am using the below Macro for copying the part of data and paste in master sheet.
Sub copy()
Application.DisplayAlerts = False
Dim i As Integer, erow As Integer, LastRow As Integer
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 16 To LastRow
If Cells(i, "J") = Date Then
Range(Cells(i, 2), Cells(i, 12)).Select
Selection.copy
Workbooks.Open Filename:="C:\Users\preet\Desktop\latest\preethi3.xlsx"
Worksheets("sheet1").Select
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Cells(erow, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
End If
Next i
MsgBox ("Task completed")
End Sub
This Macro is copying data pasting in new master sheet. But the Problem is when I am processing Macro in second sheet it is copying the sheet data to master sheet but the first sheet data is changing values.
Please see the attached sample excel sheet(Preethi sheet) and master sheet(preethi3).
I have a main folder containing 25 sub folders. daily I will add one new excel sheet to each sub folder. I want to copy part of the Excel sheet data from 25 excel sheets which are in 25 sub folders and paste in a new master excel sheet.
Then I have to upload the master excel sheet in MS Access.
I am using the below Macro for copying the part of data and paste in master sheet.
Sub copy()
Application.DisplayAlerts = False
Dim i As Integer, erow As Integer, LastRow As Integer
LastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 16 To LastRow
If Cells(i, "J") = Date Then
Range(Cells(i, 2), Cells(i, 12)).Select
Selection.copy
Workbooks.Open Filename:="C:\Users\preet\Desktop\latest\preethi3.xlsx"
Worksheets("sheet1").Select
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Cells(erow, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
End If
Next i
MsgBox ("Task completed")
End Sub
This Macro is copying data pasting in new master sheet. But the Problem is when I am processing Macro in second sheet it is copying the sheet data to master sheet but the first sheet data is changing values.
Please see the attached sample excel sheet(Preethi sheet) and master sheet(preethi3).