1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
Sub Fusion()
Dim principal As ThisWorkbook
Dim repertoire As String, fichier As String
Dim row As Integer
'Application.Calculation = xlCalculationManual
Application.EnableEvents = False
Application.ScreenUpdating = False
'Sheets("Consolidate").Activate
'repertoire = Cells(8, 2)
Sheets("Database").Activate
Application.ScreenUpdating = False
Set principal = ThisWorkbook
Sheets("Database").Activate
'Selectionne toutes les cellules de la feuille
Cells.Select 'on sélectionne tout
Range("A2:K650000").Select 'On sélectionne que ce qui concerne les données copiées
'Supprime toutes les cellules et les décales vers le haut
Selection.Delete
Application.DisplayAlerts = False
repertoire = "***"
ChDir repertoire
fichier = Dir("*.xlsm")
Do While fichier <> ""
If fichier <> principal.Name Then
Workbooks.Open fichier
On Error GoTo suivant
With Sheets(2)
On Error GoTo 0
On Error Resume Next
If .AutoFilterMode Then
.Cells.AutoFilter
End If
Sheets(2).Select
'row = Range("A" & Rows.Count).End(xlUp).row
Do While Cells(row, 7) <> "" 'Count last cell
row = row + 1
Loop
Range("A2:I" & row).Select
'MsgBox fichier & "Has opened"
'MsgBox row & " lignes"
'Range(Selection, Selection.End(xlDown)).Select
'Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
ActiveWorkbook.Close False
principal.Activate
Sheets("Database").Select
Range("A65000").End(xlUp).Offset(1).Select
ActiveSheet.Paste
'Selection.End(xlDown).Select
'ActiveCell.Offset(1, 0).Select
'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
':=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Save
'MsgBox fichier & "Has opened"
Workbook.Open (fichier)
fichier = Dir
End With
'ActiveWorkbook.Close False
End If
suivant:
If Err.Number = 9 Then MsgBox "Pas de feuille ""Data"" dans le fichier " & fichier, vbExclamation: ActiveWorkbook.Close False
'fichier = Dir
Loop
Workbook_Open 'Close all windows
Formula_DB 'Tirer les formules dans Database
'Application.Calculation = xlCalculationAutomatic
End Sub |
Partager