Sub Importfiles()
Dim NomFichier As String, Chemin As String
Chemin = "C:\Users\XXXXXXXXXX\Desktop\Repertoire test\"
NomFichier = Dir(Chemin & "*.xlsx") 'définit les fichiers à importer en l’occurence tous les fichiers excel se trouvant dans ce répertoire
Do While NomFichier <> "" 'démarre la boucle jusqu’au dernier fichier disponible dans le répertoire
Workbooks.Open Chemin & NomFichier 'ouvre le fichier actuel à importer
With ActiveSheet
.Range("F7").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("B" & .Cells(.Rows.Count, "B").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("F8").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("C" & .Cells(.Rows.Count, "C").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("F11").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("D" & .Cells(.Rows.Count, "D").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("B21").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("E" & .Cells(.Rows.Count, "E").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("B22").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("F" & .Cells(.Rows.Count, "F").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("A84").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("G" & .Cells(.Rows.Count, "G").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C94").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("H" & .Cells(.Rows.Count, "H").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C105").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("I" & .Cells(.Rows.Count, "I").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("A116").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("J" & .Cells(.Rows.Count, "J").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("D116").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("K" & .Cells(.Rows.Count, "K").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C130").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("L" & .Cells(.Rows.Count, "L").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C131").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("M" & .Cells(.Rows.Count, "M").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C132").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("N" & .Cells(.Rows.Count, "N").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C133").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("O" & .Cells(.Rows.Count, "O").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C134").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("P" & .Cells(.Rows.Count, "P").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C135").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("Q" & .Cells(.Rows.Count, "Q").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("A145").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("R" & .Cells(.Rows.Count, "R").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("A158").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("S" & .Cells(.Rows.Count, "S").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
With ActiveSheet
.Range("C169").Copy
End With
With ThisWorkbook
With .Sheets("Compile")
.Range("T" & .Cells(.Rows.Count, "T").End(xlUp).Row + 1).PasteSpecial Paste:=xlPasteValues
End With
End With
Application.DisplayAlerts = False
ActiveWorkbook.Close
NomFichier = Dir 'va vers le fichier suivant à importer
Loop 'recommece la boucle avec le fichier suivant
End Sub