Sub TriFeuilles()
Application.EnableEvents = False
Dim tabFeuille() As Variant
nb = Sheets.Count - 1
ReDim tabFeuille(1 To nb, 2)
i = 1
For Each ws In Sheets
If ws.Name <> "NOUVEAU MODELE" Then
tabFeuille(i, 1) = Split(ws.Name, " ")(0)
tabFeuille(i, 2) = Split(ws.Name, " ")(1)
i = i + 1
End If
Next ws
Tri tabFeuille(), LBound(tabFeuille, 1), UBound(tabFeuille, 1), 2, 1
LastFeuille = "NOUVEAU MODELE"
For i = LBound(tabFeuille, 1) To UBound(tabFeuille, 1)
Sheets("" & tabFeuille(i, 1) & " " & tabFeuille(i, 2) & "").Move after:=Sheets(LastFeuille)
LastFeuille = tabFeuille(i, 1) & " " & tabFeuille(i, 2)
Next i
Application.EnableEvents = True
End Sub
Sub Tri(a(), gauc, droi, Col1erTri, Col2ndTri) ' Quick sort
ref = a((gauc + droi) \ 2, Col1erTri) & a((gauc + droi) \ 2, Col2ndTri)
g = gauc: d = droi
Do
Do While a(g, Col1erTri) & a(g, Col2ndTri) < ref: g = g + 1: Loop
Do While ref < a(d, Col1erTri) & a(d, Col2ndTri): d = d - 1: Loop
If g <= d Then
For k = LBound(a, Col1erTri) To UBound(a, Col1erTri)
temp = a(g, k): a(g, k) = a(d, k): a(d, k) = temp
Next k
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi, Col1erTri, Col2ndTri)
If gauc < d Then Call Tri(a, gauc, d, Col1erTri, Col2ndTri)
End Sub
Sub TriFeuilles()
Application.EnableEvents = False
Dim tabFeuille() As Variant 'déclare un tableau
nb = Sheets.Count - 1
ReDim tabFeuille(1 To nb, 2) 'dimensionne le tableau de "nombres de feuilles -1" lignes et 2 colonnes
i = 1
For Each ws In Sheets 'pour chaque feuille du classeurs
If ws.Name <> "NOUVEAU MODELE" Then
tabFeuille(i, 1) = Split(ws.Name, " ")(0) 'première colonne prend la date
tabFeuille(i, 2) = Split(ws.Name, " ")(1) 'seconde colonne prend la ville
i = i + 1
End If
Next ws
Tri tabFeuille(), LBound(tabFeuille, 1), UBound(tabFeuille, 1), 1, 2 'on lance le tri quicksort
LastFeuille = "NOUVEAU MODELE"
For i = LBound(tabFeuille, 1) To UBound(tabFeuille, 1) 'on parcourt le tableau
Sheets("" & tabFeuille(i, 1) & " " & tabFeuille(i, 2) & "").Move after:=Sheets(LastFeuille) 'et on déplace la feuille
LastFeuille = tabFeuille(i, 1) & " " & tabFeuille(i, 2)
Next i
Application.EnableEvents = True
End Sub
Sub Tri(a(), gauc, droi, Col1erTri, Col2ndTri) ' Quick sort
ref = a((gauc + droi) \ 2, Col1erTri) & a((gauc + droi) \ 2, Col2ndTri)
g = gauc: d = droi
Do
Do While a(g, Col1erTri) & a(g, Col2ndTri) < ref: g = g + 1: Loop
Do While ref < a(d, Col1erTri) & a(d, Col2ndTri): d = d - 1: Loop
If g <= d Then
For k = LBound(a, Col2ndTri) To UBound(a, Col2ndTri)
temp = a(g, k): a(g, k) = a(d, k): a(d, k) = temp
Next k
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi, Col1erTri, Col2ndTri)
If gauc < d Then Call Tri(a, gauc, d, Col1erTri, Col2ndTri)
End Sub
qu'est ce qui est rouge??
chez moi, pas de pb..
voir PJ
Alors effectivement j'avais pas lu la question, j'ai une macro qui renome l'onglet par rapport a la cellule A1 qui doit etre dans ce sens date+ville et du coup trier tous les janviers ensemble et ainsi de suitemais il nous faut vraiment d'abord les dates.
d'ou ma question à laquelle tu n'as pas répondu.. VILLE et date ou Date puis ville...
il faut modifier deux lignes
VB:Sub TriFeuilles() Application.EnableEvents = False Dim tabFeuille() As Variant 'déclare un tableau nb = Sheets.Count - 1 ReDim tabFeuille(1 To nb, 2) 'dimensionne le tableau de "nombres de feuilles -1" lignes et 2 colonnes i = 1 For Each ws In Sheets 'pour chaque feuille du classeurs If ws.Name <> "NOUVEAU MODELE" Then tabFeuille(i, 1) = Split(ws.Name, " ")(0) 'première colonne prend la date tabFeuille(i, 2) = Split(ws.Name, " ")(1) 'seconde colonne prend la ville i = i + 1 End If Next ws Tri tabFeuille(), LBound(tabFeuille, 1), UBound(tabFeuille, 1), 1, 2 'on lance le tri quicksort LastFeuille = "NOUVEAU MODELE" For i = LBound(tabFeuille, 1) To UBound(tabFeuille, 1) 'on parcourt le tableau Sheets("" & tabFeuille(i, 1) & " " & tabFeuille(i, 2) & "").Move after:=Sheets(LastFeuille) 'et on déplace la feuille LastFeuille = tabFeuille(i, 1) & " " & tabFeuille(i, 2) Next i Application.EnableEvents = True End Sub Sub Tri(a(), gauc, droi, Col1erTri, Col2ndTri) ' Quick sort ref = a((gauc + droi) \ 2, Col1erTri) & a((gauc + droi) \ 2, Col2ndTri) g = gauc: d = droi Do Do While a(g, Col1erTri) & a(g, Col2ndTri) < ref: g = g + 1: Loop Do While ref < a(d, Col1erTri) & a(d, Col2ndTri): d = d - 1: Loop If g <= d Then For k = LBound(a, Col2ndTri) To UBound(a, Col2ndTri) temp = a(g, k): a(g, k) = a(d, k): a(d, k) = temp Next k g = g + 1: d = d - 1 End If Loop While g <= d If g < droi Then Call Tri(a, g, droi, Col1erTri, Col2ndTri) If gauc < d Then Call Tri(a, gauc, d, Col1erTri, Col2ndTri) End Sub
For Each ws In Sheets 'pour chaque feuille du classeurs
If ws.Name <> "NOUVEAU MODELE" Then
tabFeuille(i, 1) = DateSerial(Right(Split(ws.Name, " ")(0), 2), Mid(Split(ws.Name, " ")(0), 3, 2), Left(Split(ws.Name, " ")(0), 2)) 'première colonne prend la date
tabFeuille(i, 2) = Split(ws.Name, " ")(1) 'seconde colonne prend la ville
i = i + 1
End If
Next ws