Sub ExportCSV()
' ExportCSV Macro
' Touche de raccourci du clavier: Ctrl+Shift+E
'****************************
' Dans Outils, Référence cochez microsoft scripting runtime
'**************************
Dim i As Integer, Dico As New Dictionary
Dim Pl As Range, Cel As Range, Lg%
trier ' on trie 1 fois et pas a chaque tour de boucle
Lg = Range("C" & Rows.Count).End(xlUp).Row ' dernière ligne
Set Pl = Range("C2:C" & Lg) ' mise en mémoire + rapide
For Each Cel In Pl ' met tous les nombres de façon unique
If Not Dico.Exists(Cel.Text) Then Dico.Add Cel.Text, ""
Next
Application.ScreenUpdating = False ' ne met pas tout de suite excel à jour + rapide
Set Pl = Range("A1:E" & Lg) ' mise en mémoire + rapide
For i = 0 To Dico.Count - 1
Application.CutCopyMode = False
Pl.AutoFilter Field:=3, Criteria1:=Dico.Keys(i)
Pl.Copy
Workbooks.Add
DoEvents
With ActiveWorkbook
.ActiveSheet.Paste
.SaveAs Filename:=ThisWorkbook.Path & "\Num" & Dico.Keys(i) & ".csv", FileFormat:=xlCSV, CreateBackup:=False
.Saved = True
.Close
End With
Next i
Application.ScreenUpdating = True
Range("A1").CurrentRegion.AutoFilter Field:=3
End Sub
Sub trier()
With ActiveWorkbook.Worksheets("test").Sort ' j'ai oté autofilter
.SortFields.Clear
.SortFields.Add Range("C1"), xlSortOnValues, xlAscending, xlSortNormal
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub