grazie ad Anthony è stato risolto il thread precedente:
http://www.pc-facile.com/forum/viewtopic.php?f=26&t=108584
Ma vista la complessità dello script NON riesco a capire dove modificarlo per adatarlo ad una nuova esigente.
- Codice: Seleziona tutto
Sub MeseImport()
Dim DBPath As String, myCFile As String, mySplit, mySh As String, myD As Date, myT As String
Dim I As Long, mErr As String, dbSh As Worksheet, myLast As Long, daImp, myMatch
'
DBPath = "D:\FORNI_2017\GIUGNO" '<<< La directory da cui importare
daImp = Array("T09", "T10", "T11", "T12") '<<< L'elenco dei forni da importare
'
mySplit = Split(DBPath, "\", , vbTextCompare)
mySh = "DataBase_" & Format(CDate("01/" & mySplit(UBound(mySplit)) & "/" & Right(mySplit(UBound(mySplit) - 1), 4)), "MmmYY")
Sheets(mySh).Select
If Right(DBPath, 1) <> "\" Then DBPath = DBPath & "\"
Set dbSh = ThisWorkbook.Sheets(mySh)
'Azzera l'area di importazione:
Range("A2:C20000,E2:G20000").ClearContents
'Importa:
myCFile = Dir(DBPath & "*.xls*")
Do
myMatch = Application.Match(Left(myCFile, 3), daImp, 0)
Application.ScreenUpdating = False
If myCFile = "" Then Exit Do
If Not IsError(myMatch) Then
On Error Resume Next
Debug.Print myCFile, Timer
Workbooks.Open Filename:=(DBPath & myCFile), UpdateLinks:=False, ReadOnly:=True
On Error GoTo 0
If ActiveWorkbook.Name = ThisWorkbook.Name Then
mErr = mErr & vbCrLf & DBPath & myCFile
Else
Sheets(1).Select
For I = 5 To Cells(Rows.Count, 1).End(xlUp).Row + 50
' Debug.Print I, Timer
DoEvents
myLast = dbSh.Cells(Rows.Count, 1).End(xlUp).Row
myD = Cells(I, 1).MergeArea.Range("A1").Value
If myD > Int(Now) Then Exit For
myT = Cells(I, 2).MergeArea.Range("A1").Value
If myT <> "" Then
If myD = dbSh.Cells(myLast, 1) And myT = dbSh.Cells(myLast, 3) Then
dbSh.Range("E" & myLast).Value = dbSh.Range("E" & myLast).Value + Cells(I, "L").Value
dbSh.Range("F" & myLast).Value = dbSh.Range("F" & myLast).Value + Cells(I, "O").Value
dbSh.Range("G" & myLast).Value = dbSh.Range("G" & myLast).Value + Cells(I, "P").Value
Else
myLast = myLast + 1
dbSh.Cells(myLast, "A").Value = myD
dbSh.Cells(myLast, "B").Value = ActiveSheet.Name
dbSh.Cells(myLast, "C").Value = myT
dbSh.Cells(myLast, "E").Value = Cells(I, "L").Value
dbSh.Cells(myLast, "F").Value = Cells(I, "O").Value
dbSh.Cells(myLast, "G").Value = Cells(I, "P").Value
End If
End If
Next I
Workbooks(myCFile).Close False
Application.ScreenUpdating = True: DoEvents
End If
Else
Beep
End If
myCFile = Dir
Loop
Application.ScreenUpdating = True
If Len(mErr) > 3 Then
MsgBox ("Completato, eccetto i seguenti file:" & vbCrLf & mErr)
Else
MsgBox ("Completato")
End If
End Sub
In pratica và tutto bene tranne che quando è il momento di copiare i dati in Masterdata i valori da prelevare sono tutti quelli da colonna A a colonna AE (escludendo le colonne E - F).
Tutte le prove fatte finora hanno solo causato un superlavoro al DEBUG

Grazie in anticipo.