Option Explicit
Private Sub ConcatenationCSV(sDossier As String)
Dim Wkb As Workbook
Dim sChemin As String, sFichier As String
Dim LastRow As Long, iRow As Long
Dim c As Range, Ar() As String
Const sSeparateur As String = ";"
Application.ScreenUpdating = False
sChemin = sDossier & "\"
sFichier = Dir$(sChemin & "*.csv" )
Feuil1.Cells.Clear
Do While Len(sFichier) > 0
Set Wkb = Workbooks.Open(sChemin & sFichier)
LastRow = Wkb.Sheets(1).Cells(Wkb.Sheets(1).Rows.Count, 1).End(xlUp).Row
With Feuil1
For Each c In Wkb.Sheets(1).Range("A1:A" & LastRow)
iRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
Ar = Split(c, sSeparateur)
.Range(.Cells(iRow, 1), .Cells(iRow, UBound(Ar) + 1)).Value = Ar
Next c
End With
Wkb.Close
Set Wkb = Nothing
sFichier = Dir$()
Loop
Application.ScreenUpdating = True
End Sub
Sub SelDossierCSV()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "Dossier CSV à traiter"
.AllowMultiSelect = False
.ButtonName = "Sélection Dossier"
.Show
If .SelectedItems.Count > 0 Then
DoEvents
ConcatenationCSV .SelectedItems(1)
End If
End With
End Sub |