Hello all,
I am trying to create a macro, to do this:
- macro will be placed on a new workbook, called "final". this workbook will have a lot of sheets "munchen", "wien", "paris" etc.
- when run, the macro will find the newest file in a folder , will open the file, copy some data from every sheet and paste it on workbook "final", sheet "munchen"
- after this, it will find the newest file in another folder, open the file, copy data from every sheet and paste it in workbook "final", sheet "wien"
etc etc
I managed to create something, but considering the fact that i have around 80-90 sheets, i think that it must be a easier solution
This is what i have right now...
Thank you!
I am trying to create a macro, to do this:
- macro will be placed on a new workbook, called "final". this workbook will have a lot of sheets "munchen", "wien", "paris" etc.
- when run, the macro will find the newest file in a folder , will open the file, copy some data from every sheet and paste it on workbook "final", sheet "munchen"
- after this, it will find the newest file in another folder, open the file, copy data from every sheet and paste it in workbook "final", sheet "wien"
etc etc
I managed to create something, but considering the fact that i have around 80-90 sheets, i think that it must be a easier solution
This is what i have right now...
Thank you!
Code:
<code style="margin: 0px; padding: 0px; font-style: inherit; font-weight: inherit; line-height: 12px;">Sub ACT()
Dim MyPath As String
Dim MyFile As String
Dim LatestFile As String
Dim LatestDate As Date
Dim LMD As Date
MyPath = "C:\Users\computer\Desktop\test\cerere"
If Right(MyPath, 1) <> "" Then MyPath = MyPath & ""
MyFile = Dir(MyPath & "*.xls", vbNormal)
If Len(MyFile) = 0 Then
MsgBox "No file found!", vbExclamation
Exit Sub
End If
Do While Len(MyFile) > 0
LMD = FileDateTime(MyPath & MyFile)
If LMD > LatestDate Then
LatestFile = MyFile
LatestDate = LMD
End If
MyFile = Dir
Loop
Workbooks.Open MyPath & LatestFile, ReadOnly:=True
ThisWorkbook.Worksheets("MUNCHEN").Range("A2:C2").Value = ActiveWorkbook.Worksheets("123").Range("A5:C5").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("E2:F3").Value = ActiveWorkbook.Worksheets("123").Range("D12:E13").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("A5:C5").Value = ActiveWorkbook.Worksheets("234").Range("A5:C5").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("E5:F6").Value = ActiveWorkbook.Worksheets("234").Range("D12:E13").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("A8:C8").Value = ActiveWorkbook.Worksheets("345").Range("A5:C5").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("E8:F9").Value = ActiveWorkbook.Worksheets("345").Range("D12:E13").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("A11:C11").Value = ActiveWorkbook.Worksheets("456").Range("A5:C5").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("E11:F12").Value = ActiveWorkbook.Worksheets("456").Range("D12:E13").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("A14:C14").Value = ActiveWorkbook.Worksheets("567").Range("A5:C5").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("E14:F15").Value = ActiveWorkbook.Worksheets("567").Range("D12:E13").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("A17:C17").Value = ActiveWorkbook.Worksheets("678").Range("A5:C5").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("E17:F18").Value = ActiveWorkbook.Worksheets("678").Range("D12:E13").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("A20:C20").Value = ActiveWorkbook.Worksheets("789").Range("A5:C5").Value
ThisWorkbook.Worksheets("MUNCHEN").Range("E20:F21").Value = ActiveWorkbook.Worksheets("789").Range("D12:E13").Value</code>