Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Matteo,
Poiché i due file di esempio che hai caricati sono molto schematico e priva di dettagli, il mio codice deve necessariamente essere anche schematico. Tuttavia, per ogni ordine, il codice seguente inserisce i dettagli dell'ordine nella posizione indicata nel file modello e salva quel file con il nome del cliente la data corrente.
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim srcWB As Workbook, destWB As Workbook
Dim srcSH As Worksheet, destSH As Worksheet
Dim srcRng As Range, destRng As Range, rCell As Range
Dim sNome As String
Dim dVal As Double
Dim LRow As Long
Dim CalcMode As Long
Const NomeDelFileModello As String = _
"Matteo Modello20151019.xlsx" '<<=== Modifica
Set srcWB = ThisWorkbook
Set srcSH = srcWB.Sheets("Foglio1") '<<=== Modifica
On Error GoTo XIT
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With srcSH
LRow = LastRow(srcSH, .Columns("A:A"))
Set srcRng = .Range("A2:A" & LRow)
End With
For Each rCell In srcRng.Cells
Set destWB = Workbooks.Open(NomeDelFileModello)
Set destSH = destWB.Sheets("Foglio1") '<<=== Modifica
Set destRng = destSH.Range("A3")
With rCell
sNome = .Offset(0, 1).Value
dVal = .Offset(0, 2).Value
destRng.Value = dVal
With destWB
.SaveAs Filename:=sNome & Format(Date, "yyyymmdd"), _
FileFormat:=.FileFormat
.Close SaveChanges:=False
End With
End With
Next rCell
XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range)
If Rng Is Nothing Then
Set Rng = SH.Cells
End If
On Error Resume Next
LastRow = Rng.Find(What:="*", _
after:=Rng.Cells(1), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
'<<=========
===
Regards,
Norman