Private Sub Worksheet_Change(ByVal Target As Range)
Dim P As Range, i&, r As Range, mini&
If Intersect(Target, [S5]) Is Nothing Then Exit Sub
Application.ScreenUpdating = False
Application.EnableEvents = False 'désactive les évènements
On Error Resume Next 'si aucune SpecialCell
[S5] = Val(CStr([S5])) 'au cas où...
Set P = [A6:R600] 'plage adaptable
P.Columns(7).Resize(, 12) = "" 'RAZ
For i = 1 To P.Rows.Count
If P(i, 2) <> "" Then
Range("G2:R2") = "=SEARCH(""" & P(i, 1) & """,G1)" 'analyse des disponibilités
'---M.Armant (on commence par lui car c'est le moins disponible)---
If P(i, 5) <> "" Then
Set r = Nothing
Set r = Range("G2,N2").SpecialCells(xlCellTypeFormulas, 1)
If Not r Is Nothing Then
mini = Application.Min(Intersect(r.EntireColumn, Rows(3))) 'minimum en ligne 3
For Each r In r
If r(2) = mini Then r(i + 4) = P(i, 5): Exit For
Next r
End If
End If
End If
'---M.Yuste---
If P(i, 3) <> "" Then
If P(i, 14) = P(i, 3) Then Range("M2") = "" 'neutralise la colonne M si doublon
Set r = Nothing
Set r = Range("H2:M2").SpecialCells(xlCellTypeFormulas, 1)
If Not r Is Nothing Then
mini = Application.Min(Intersect(r.EntireColumn, Rows(3))) 'minimum en ligne 3
For Each r In r
If r(2) = mini Then r(i + 4) = P(i, 3): Exit For
Next r
End If
End If
'---Mme Querat---
If P(i, 4) <> "" Then
If P(i, 13) = P(i, 4) Or P(i, 14) = P(i, 4) Then Range("O2") = "" 'neutralise la colonne O si doublon
Set r = Nothing
Set r = Range("O2:R2").SpecialCells(xlCellTypeFormulas, 1)
If Not r Is Nothing Then
mini = Application.Min(Intersect(r.EntireColumn, Rows(3))) 'minimum en ligne 3
For Each r In r
If r(2) = mini Then r(i + 4) = P(i, 4): Exit For
Next r
End If
End If
Next i
'[G2:R2] = "" 'facultatif, mettre en commentaire pour voir les formules
Application.EnableEvents = True 'réactive les évènements
End Sub