Hello - I currently have a loop code that is copying data from multiple workbooks into a master workbook. The problem is I need it to copy the data from each workbook and paste it into its corresponding sheet.
For instance, the data from the workbook "Aberdeen" I would like to go in the data sheet labeled "Aberdeen", and so on. The sheets are in the same order as the workbooks are opened so I could just have it copy into the next sheet after "Aberdeen" and so on. Names would not have to be a factor.
Please see code below
Sub Create_Month_Summary()
Dim folderPath As String
Dim fileName As String
Dim thisWorkbook As Workbook
Dim dayNumber As Integer
Dim workbookDate As Date
Dim rowOffset As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Folder containing daily dated workbooks for a month - CHANGE AS REQUIRED
folderPath = "P:\PROJECT\XATA Data Tracking\Activity Reports"
Set thisWorkbook = ActiveWorkbook
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
rowOffset = 0
fileName = Dir(folderPath & "*.xlsm")
Do While fileName <> ""
'Copy data from dated workbook to associated row in summary sheet
Workbooks.Open folderPath & fileName
With thisWorkbook.Sheets("Aberdeen").Range("A1:C100")
.Offset(rowOffset, 0).Value = Sheets("Trailer Summary").Range("A8:C100").Value
End With
ActiveWorkbook.Close savechanges:=False
'Get next file name
fileName = Dir
Loop
MsgBox "Finished"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Please let me know if this is not clear, thanks!
For instance, the data from the workbook "Aberdeen" I would like to go in the data sheet labeled "Aberdeen", and so on. The sheets are in the same order as the workbooks are opened so I could just have it copy into the next sheet after "Aberdeen" and so on. Names would not have to be a factor.
Please see code below
Sub Create_Month_Summary()
Dim folderPath As String
Dim fileName As String
Dim thisWorkbook As Workbook
Dim dayNumber As Integer
Dim workbookDate As Date
Dim rowOffset As Long
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Folder containing daily dated workbooks for a month - CHANGE AS REQUIRED
folderPath = "P:\PROJECT\XATA Data Tracking\Activity Reports"
Set thisWorkbook = ActiveWorkbook
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
rowOffset = 0
fileName = Dir(folderPath & "*.xlsm")
Do While fileName <> ""
'Copy data from dated workbook to associated row in summary sheet
Workbooks.Open folderPath & fileName
With thisWorkbook.Sheets("Aberdeen").Range("A1:C100")
.Offset(rowOffset, 0).Value = Sheets("Trailer Summary").Range("A8:C100").Value
End With
ActiveWorkbook.Close savechanges:=False
'Get next file name
fileName = Dir
Loop
MsgBox "Finished"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Please let me know if this is not clear, thanks!