Sub Formater_Equipe()
Dim Postes(1 To 5), CouleursFond(1 To 5)
Dim i, j, K
Dim xSh As Worksheet, NbJoueurs
'lecture des postes et de leur couleur de fond
For i = 1 To 5
Postes(i) = Sheets("base").Cells(1 + i, 3)
CouleursFond(i) = Sheets("base").Cells(1 + i, 3).Interior.Color
Next i
'boucle sur les feuilles d'équipe
For Each xSh In Worksheets
If Not (xSh.Name = "divisions_conférences" Or xSh.Name = "base" Or _
xSh.Name = "vierge") Then
With xSh
xSh.Activate
NbJoueurs = .Range("D65536").End(xlUp).Row - 1
'boucle pour remplacer le libellé du poste par le rang du poste
For i = 2 To NbJoueurs + 1
For j = 1 To 5
If .Cells(i, 3) = Postes(j) Then
.Cells(i, 3) = j
Exit For
End If
Next j
Next i
'tri du tableau
.Range("B1:S" & NbJoueurs + 1).Sort key1:=.Range("C1"), Order1:=xlAscending, _
key2:=.Range("B1"), Order2:=xlAscending, key3:=.Range("D1"), Order3:=xlAscending, _
Header:=xlYes
'boucle pour remplacer rang du poste par le libellé du poste
'et colorer le fond
For i = 2 To NbJoueurs + 1
.Range("B" & i & ":S" & i).Interior.Color = CouleursFond(.Cells(i, 3))
.Cells(i, 3) = Postes(.Cells(i, 3))
Next i
End With
End If
Next xSh
End Sub