Sub RapatrieR()
Dim Ligne As Long, Cible As Long, Deb As Long
Dim Fichier As String, DerniéreSem As Long
lg = 1
With ThisWorkbook.Sheets("Recap")
.Visible = True
.Range("A2:AC65000").ClearContents
End With
Fichier = Dir(ThisWorkbook.Path & "\" & "*.csv")
DerniéreSem = InputBox("N° dernière semaine")
If Not IsNumeric(DerniéreSem) Then MsgBox "Semaine non renseignée ou de façon incorrecte, sortie du traitement ": Exit Sub
Do Until Fichier = ""
If clng(Mid(Fichier, 3, 2)) <= DerniéreSem Then
Workbooks.OpenText ThisWorkbook.Path & "\" & Fichier, Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, Local:=True, Semicolon:=True
With ActiveWorkbook.ActiveSheet
Ligne = .Range("A" & .Rows.Count).End(xlUp).Row - 1
If ThisWorkbook.Sheets("Recap").Range("A2") <> "" Then
Cible = ThisWorkbook.Worksheets("Recap").Range("A" & ThisWorkbook.Worksheets("Recap").Rows.Count).End(xlUp).Row + 1
Deb = 10
Else
Cible = 1
Deb = 9
End If
ThisWorkbook.Sheets("Recap").Range("A" & Cible & ":AC" & Ligne + Cible - Deb) = .Range("A" & Deb & ":AC" & Ligne).Value
End With
ThisWorkbook.Sheets("Recap").Range("AN" & lg) = Fichier: lg = lg + 1: ThisWorkbook.Sheets("Recap").Range("AN" & lg) = ""
Workbooks(Fichier).Close
Fichier = Dir
End If
Loop
Sheets("Recap").Visible = False
Sheets("Resultats").Select
End Sub