Sub Organiser()
Dim Pchoix As Range, P As Range, rc As Byte, cc As Byte
Dim n As Byte, col As Byte, lig As Byte, c As Range
Dim test As Boolean, n1 As Integer, c1 As Range
Set Pchoix = Sheets("Choix").[A3:Q362]
If Application.Count(Pchoix) < Pchoix.Rows.Count * (Pchoix.Columns.Count - 1) _
Then MsgBox "La plage des choix n'est pas correctement remplie...": Exit Sub
Application.ScreenUpdating = False
Set P = [A4:O27] '1ère session
rc = P.Rows.Count
cc = P.Columns.Count
P.EntireRow.ClearContents 'RAZ
For n = 1 To 3 'les 3 sessions
If n > 1 Then Set P = P.Offset(, cc) 'plage décalée
For col = 1 To cc
Pchoix.Sort Pchoix.Columns(col + 2), xlAscending, Header:=xlNo 'tri
lig = 1
For Each c In Pchoix.Columns(2).Cells
test = Application.CountIf(P, c) = 0
If test Then
For n1 = 1 To n - 1 'pour ne pas participer plus d'une fois au même club
If Application.CountIf(P.Columns(col).Offset(, cc * (n1 - n)), c) _
Then test = False: Exit For
Next
If test Then
P(lig, col) = c
lig = lig + 1
If lig > rc Then Exit For
End If
End If
Next c
Next col
'si la plage P n'est pas entièrement remplie on la complète :
If Application.CountA(P) < P.Count Then
For Each c1 In P.SpecialCells(xlCellTypeBlanks)
For Each c In Pchoix.Columns(2).Cells
If Application.CountIf(P, c) = 0 Then c1 = c: Exit For
Next c
Next c1
End If
Next n
Pchoix.Sort Pchoix.Columns(1), xlAscending, Header:=xlNo 'tri sur colonne A
End Sub