Option Explicit
Sub affiancaFiles1()
Dim FD As FileDialog, MyRange As Range, File As Variant, sh As Byte, LC As Integer, _
W1 As Workbook, W2 As Workbook
Set MyRange = [a1:gd100]
Set W1 = ActiveWorkbook
Set FD = Application.FileDialog(msoFileDialogFilePicker)
With FD
.AllowMultiSelect = True 'posso selezionare più files
.Show
Application.ScreenUpdating = False 'Conviene spegnere lo schermo
For Each File In .SelectedItems 'Il ciclo esterno scorre tutti i files selezionati
Workbooks.Open File
Set W2 = ActiveWorkbook
For sh = 1 To Worksheets.Count 'Il ciclo interno scorre tutti i fogli di ogni singolo file
' In ogni foglio prende l'intervallo A3:D20 e lo incolla nel corrispondente foglio del file di riepilogo
W2.Worksheets(sh).Range(MyRange.Address).Copy
If W1.Worksheets(2).Cells(3, 1).End(xlToRight).Column = Columns.Count Then
W1.Activate
UC = ActiveSheet.UsedRange.SpecialCells(xlLastCell, xlNumbers).Column
W1.Worksheets(2).Cells(3, UC).PasteSpecial xlPasteAll
Else
LC = W1.Worksheets(2).Cells(3, 1).End(xlToRight).Offset(, 1).Column
W1.Worksheets(2).Cells(3, LC).PasteSpecial xlPasteAll
End If
Next
W2.Close savechanges:=False
Next
End With
Application.ScreenUpdating = True
End Sub
|