Option Explicit
Dim DocDép, k, NomClasse, Onglet
Sub UneClasseParOnglet()
Call Macro_tri
Application.ScreenUpdating = False
Set DocDép = ActiveSheet
'
' Initialisation : On supprime les onglets de classe éventuellement existant
For Each Onglet In Worksheets
Application.DisplayAlerts = False
If Onglet.Name <> "carac" Then
Sheets(Onglet.Name).Activate
ActiveWindow.SelectedSheets.Delete
End If
Next Onglet
'Routine qui recrée les onglets
k = 0
While Worksheets("carac").Cells(2 + k, 1).Value <> ""
If Worksheets("carac").Cells(2 + k, 1).Value <> Worksheets("carac").Cells(1 + k, 1).Value Then '
NomClasse = Sheets("carac").Cells(2 + k, 1).Value
Sheets.Add After:=Sheets(Sheets.Count) 'On ouvre un nouvel onglet
ActiveSheet.Name = NomClasse 'on renomme l'onglet
Application.StatusBar = NomClasse
Sheets("carac").Rows(1).Copy Cells(1, 1)
End If
Sheets(NomClasse).Activate
'Sheets(NomClasse).Cells(Cells(65000, 1).End(xlUp).Row + 1, 1).Select
Worksheets("carac").Rows(2 + k).Copy Worksheets(NomClasse).Cells(Cells(65000, 1).End(xlUp).Row + 1, 1)
DocDép.Activate
k = k + 1
Wend
Application.StatusBar = ""
Beep
End Sub