Una famiglia di software per fogli di calcolo Microsoft con strumenti per l'analisi, la creazione di grafici e la comunicazione dei dati.
Ciao Ale,
In un modulo standard del tuo file Personal.xlsb, incolla il seguente codice:
'=========>>
Option Explicit
'--------->>
Public Sub Tester()
Dim srcWB As Workbook, destWB As Workbook
Dim SH As Worksheet
Dim srcSH As Worksheet, srcSH2 As Worksheet
Dim destSH As Worksheet, destSH2 As Worksheet
Dim srcRng As Range, destRng As Range, rCell As Range
Dim sPath As String, sStr As String
Dim sCognome As String, sFullName As String
Dim iRow As Long, jRow As Long
Dim i As Long, j As Long
Dim CalcMode As Long, NumberOfSheets As Long
Const sPrimoFoglio As String = "Foglio1"
Const sSecondoFoglio As String = "Foglio2"
Const sPercorsoDestinazione As String = _
"C:\Users\Ale\Pippo" '<<=== Modifica
Const sEstensione As String = ".xlsx"
Set srcWB = ActiveWorkbook
On Error GoTo XIT
With Application
.ScreenUpdating = False
CalcMode = .Calculation
.Calculation = xlCalculationManual
.EnableEvents = False
sStr = .PathSeparator
NumberOfSheets = .SheetsInNewWorkbook
.SheetsInNewWorkbook = 2
End With
If Right(sPercorsoDestinazione, 1) = sStr Then
sPath = sPercorsoDestinazione
Else
sPath = sPercorsoDestinazione & sStr
End If
With srcWB
Set srcSH = .Sheets(sPrimoFoglio)
Set srcSH2 = .Sheets(sSecondoFoglio)
End With
For Each SH In srcWB.Worksheets( _
VBA.Array(srcSH.Name, srcSH2.Name))
With SH
iRow = LastRow(SH, .Columns("C:C"))
On Error Resume Next
Set srcRng = .Range("C2:C" & iRow)
On Error GoTo XIT
If Not srcRng Is Nothing Then
For Each rCell In srcRng.Cells
With rCell
sCognome = .Value
sFullName = sPath & sCognome & sEstensione
If FileExists(sFullName) Then
Set destWB = Workbooks.Open(sFullName)
Else
Set destWB = Workbooks.Add
With destWB
.Sheets(1).Name = sPrimoFoglio
.Sheets(2).Name = sSecondoFoglio
.SaveAs Filename:=sFullName, FileFormat:=51
End With
End If
Set srcRng = Application.Intersect(.EntireRow, SH.UsedRange)
End With
Set destSH = destWB.Sheets(SH.Name)
With destSH
jRow = LastRow(destSH, .Columns("A:A"), 1)
Set destRng = .Range("A" & jRow + 1)
End With
srcRng.Copy Destination:=destRng
destWB.Close SaveChanges:=True
Next rCell
End If
End With
Set srcRng = Nothing
Next SH
XIT:
With Application
.Calculation = CalcMode
.ScreenUpdating = True
.SheetsInNewWorkbook = NumberOfSheets
.EnableEvents = True
End With
End Sub
'--------->>
Public Function LastRow(SH As Worksheet, _
Optional Rng As Range, _
Optional minRow As Long = 1)
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
If LastRow < minRow Then
LastRow = minRow
End If
End Function
'--------->>
Public Function FileExists(FPath As String) As Boolean
Dim FName As String
FName = Dir(FPath)
FileExists = FName <> ""
End Function
'<<=========
Assegna la macro Teste r a un pulsante sulla barra di accesso rapido come spiegato QUI
Per eseguire la macro, assicurarti che il file giornaliero sia il file attivo e quindi fai clic sul pulsante macro sulla barra di accesso rapido.
===
Regards,
Norman