Bonjour
Dans la feuille Capacité de spécialité en colonne D tu mets en D2 "Nombre maximum d'éleves dans la spécialité"
Donc en D3 23 en D4 23 ...
Puis voici la macro
Sub toto()
Dim choix(1 To 4) As Variant
With Sheets("Base")
For i = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
moyenne = .Range("C" & i)
For j = 1 To 4
If .Cells(i, j + 3) <> "" Then
's'il a la moyenne pour son choix
If Application.VLookup(.Cells(i, j + 3), Sheets("Capacite de specialité").Range("B3:D12"), 2, False) < moyenne Then
'choppe la colonne correspondant au choix pour aller verifier si le nb max est atteint
colonne = Asc(.Cells(i, j + 3)) - 64
If Sheets("Resultat").Cells(Sheets("Resultat").Rows.Count, colonne).End(xlUp).Row < Application.VLookup(.Cells(i, j + 3), Sheets("Capacite de specialité").Range("B3:D12"), 3, False) + 1 Then
Sheets("Resultat").Cells(Sheets("Resultat").Cells(Sheets("Resultat").Rows.Count, colonne).End(xlUp).Row + 1, colonne) = Sheets("Base").Range("B" & i)
Exit For
End If
End If
End If
Next j
Next i
End With
End Sub