Re : classement
bonjour
nouvau code
le résultat est ds la feuille toutes perfs
attention,il y avait un espace ds la colonne H,académie
Option Compare Text
Private Sub EpNumToText(Optional Test As Boolean)
Dim Cel As Range, LetCol As String, Ws As Worksheet, Col As Byte
LetCol = IIf(Test, "C", "I")
Col = IIf(Test, 0, 9)
Set Ws = IIf(Test, Worksheets("toutes perfs"), ActiveSheet)
Application.ScreenUpdating = False
'change numeric colonne I en texte,colonne R
For Each Cel In Ws.Range(LetCol & "1:" & LetCol & Ws.Range(LetCol & "65536").End(xlUp).Row)
Select Case Cel
Case 17, 18, 19, 20
Cel.Offset(0, Col) = "lancer"
Case 13, 14, 15, 16
Cel.Offset(0, Col) = "saut"
Case 7, 8
Cel.Offset(0, Col) = "relais"
Case Is <= 6
Cel.Offset(0, Col) = "course"
Case 9, 10, 11, 12
Cel.Offset(0, Col) = "course"
End Select
Next Cel
Application.ScreenUpdating = True
End Sub
Private Sub PerfClasser()
Dim L As Long, La As Long, Le As Long, Li As Long, Ws As Worksheet, Item
Dim MonDico As Object, Cel As Range, D As Long, F As Long, D1 As Long, F1 As Long
Dim Academie, Ep, Ligne, NbE As Byte
Application.ScreenUpdating = False
Set Ws = Worksheets("toutes perfs")
Test = False
Ws.Range("A1").CurrentRegion.ClearContents 'Range("A1:N" & Ws.Range("A65536").End(xlUp).Row)
'feuille résultats
L = Range("A65536").End(xlUp).Row
Range("A1:R" & L).Sort Key1:=Range("R2"), Order1:=xlAscending, _
Key2:=Range("H2"), Order2:=xlAscending, Header:=xlGuess
Set MonDico = CreateObject("Scripting.Dictionary")
For Each Cel In Range("R2:R" & L) 'epreuve
If Not MonDico.Exists(Cel.Value) Then MonDico.Add Cel.Value, Cel.Value
Next Cel
ReDim Ep(1 To MonDico.Count, 1 To 3)
For Each Item In MonDico.items
Le = Le + 1: Ep(Le, 1) = Item
Next Item
For Le = LBound(Ep, 1) To UBound(Ep, 1)
Set Cel = Columns("R").Find(Ep(Le, 1))
If Not Cel Is Nothing Then
If Le = 1 Then Ep(Le, 2) = 1 Else Ep(Le, 2) = Cel.Row '1ère ligne
End If
Ep(Le, 3) = Application.CountIf(Range("R2:R" & L), "=" & Ep(Le, 1)) ' + Ep(Le, 3) - 1
Ep(Le, 3) = (Ep(Le, 3) + Ep(Le, 2)) - 1
Next Le
For Le = LBound(Ep, 1) To UBound(Ep, 1)
'nbre maxi ep
Select Case Ep(Le, 1)
Case "course"
NbE = 15
Case "lancer"
NbE = 8
Case "relais"
NbE = 1
Case "saut"
NbE = 12
End Select
Set MonDico = CreateObject("Scripting.Dictionary")
For Each Cel In Range("H" & Ep(Le, 2) & ":H" & Ep(Le, 3))
If Cel.Offset(0, 10) = Ep(Le, 1) Then
If Not MonDico.Exists(Cel.Value) Then MonDico.Add Cel.Value, Cel.Value
End If
Next Cel
Academie = MonDico.items
For La = LBound(Academie, 1) To UBound(Academie, 1)
F = Application.CountIf(Range("H" & Ep(Le, 2) & ":H" & Ep(Le, 3)), "=" & Academie(La))
Set Cel = Range("H" & Ep(Le, 2) & ":H" & Ep(Le, 3)).Find(Academie(La))
If Not Cel Is Nothing Then D = Cel.Row
Lr = Ws.Range("A65536").End(xlUp).Row '1ère ligne coller
Range("B" & D & ":N" & D + F - 1).Copy Destination:=Ws.Range("A" & Lr)
Li = Ws.Range("A65536").End(xlUp).Row 'dernière ligne après coller
If Li > Lr Then Ws.Range("A" & Lr & ":M" & Li).Sort Key1:=Ws.Range("M" & D), Order1:=xlDescending
If Li - Lr > NbE Then
Li = Lr + NbE
Ws.Range("A" & Li & ":M" & Ws.Range("A65536").End(xlUp).Row).ClearContents
End If
Ws.Range("N" & Ws.Range("A65536").End(xlUp).Row + 1) = La
Next La
Next Le
With Ws
.Columns("I:L").Delete Shift:=xlToLeft
.Columns("B:F").Delete Shift:=xlToLeft
.Columns("E").ClearContents
.Rows(1).Insert
.Cells(1, 1) = "Dossard"
.Cells(1, 2) = "Académie"
.Cells(1, 3) = "Epreuve"
.Cells(1, 4) = "Points"
.Columns("A😀").AutoFit
End With
EpNumToText True
L = Ws.Range("A65536").End(xlUp).Row
Ws.Range("A1😀" & L).Sort Key1:=Ws.Range("B2"), Order1:=xlAscending, Header:=xlGuess
Application.ScreenUpdating = True
End Sub
'change numeric colonne I dans colonne N en texte:exemple 1 à 6=course
Private Sub CommandButton1_Click()
EpNumToText
End Sub
Private Sub CommandButton2_Click()
PerfClasser
End Sub
à bientôt