Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Andrea,
l'esecuzione è proprio quello che stavo cercando :) Grazie mille!
Bene!
Ho però due problemi:
- non riesco a capire come generare la compilazione di un nuovo foglio
Non capisco quello che intendi! Com'è stato scritto il codice, il modulo sul foglio Sheet1 del file PROTOTIPO 2.xlsx viene riempito con i dati di interesse dall'ultima riga del foglio SORGENTE & COMPILAZIONE DATI del file in cui si trova il codice, ovvero, in questo caso, il file PROTOTIPO 1.xlsm.
quando compilo una nuova riga
- mi si verifica il seguente errore:
[...]
Avevo sviluppato il codice nel file che hai caricato il qiale non utilizzava Option Explicit come impostazione predefinita, ho trascurato di definire la variabile iCtr.
Quindi, sostituisci il codice con la versione qui sotto, nella quale ho approfittato per fare due piccole modifiche analoghe:
'=========>>
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 arrColonne As Variant
Dim sPercorso As String, sFileName As String, sCol As String
Dim i As Long, uCtr As Long, LRow As Long
Dim ictr As Long
Dim CalcMode As Long
Const sDestFile As String = "PROTOTIPO 2.xlsx"
Const sFoglioSorgente As String = _
"SORGENTE & COMPILAZIONE DATI"
Const sFoglioDestinazione As String = "Sheet1"
Const sColonneSorgente As String = _
"A,B,E,F,G,H,I,J"
Const sIntervalloDestinazione As String = _
"J14,A23,E7,K7,K9,J12,J13,E11"
Set srcWB = ThisWorkbook
sPercorso = srcWB.Path & Application.PathSeparator
sFileName = sPercorso & sDestFile
If Not IsWorkBookOpen(sDestFile) Then
Workbooks.Open sFileName
End If
Set destWb = Workbooks(sDestFile)
Set srcSH = srcWB.Sheets(sFoglioSorgente)
Set destSH = destWb.Sheets(sFoglioDestinazione)
arrColonne = Split(sColonneSorgente, ",")
With srcSH
LRow = LastRow(srcSH, .Columns("A:A"))
Set srcRng = .Rows(2)
End With
Set destRng = destSH.Range(sIntervalloDestinazione)
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
For Each rCell In destRng.Cells
ictr = ictr + 1
sCol = arrColonne(ictr - 1)
rCell.Value = srcSH.Cells(LRow, sCol).Value
Next rCell
XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1, _
Optional sPassword As String)
Dim bProtected As Boolean
With SH
If Rng Is Nothing Then
Set Rng = .Cells
End If
bProtected = .ProtectContents = True
If bProtected Then
.Unprotect Password:=sPassword
End If
End With
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
If LastRow < minRow Then
LastRow = minRow
End If
If bProtected Then
SH.Protect Password:=sPassword, _
UserInterfaceOnly:=True
End If
End Function
'--------->>
Public Function IsWorkBookOpen( _
ByRef sWbName As String) As Boolean
On Error Resume Next
IsWorkBookOpen = Not (Application.Workbooks(sWbName) Is Nothing)
End Function
'<<=========
Ho aggionato i miei file di prova Andrea20171030,zip
===
Regards,
Norman