Bonjour,
macro adaptée pour inclure le test demandé
Sub affectsalle()
Set wsd = Worksheets("données")
dld = wsd.Cells(Rows.Count, 3).End(xlUp).Row
Set wsp = Worksheets("ParamSALLES")
dlp = wsp.Cells(Rows.Count, 1).End(xlUp).Row
If dld - 1 > Application.WorksheetFunction.Sum(wsp.Range("C2:C" & dlp)) Then MsgBox "pas assez de place dans les salles pour tout ce monde": Exit Sub
For j = 2 To dlp
wsp.Cells(j, 5) = wsp.Cells(j, 3)
Next j
Set wsa = Worksheets("AFFECTATIONS")
dla = 1
For i = 2 To dld
dla = dla + 1
wsa.Cells(dla, 1) = wsd.Cells(i, 1)
wsa.Cells(dla, 2) = wsd.Cells(i, 2)
wsa.Cells(dla, 3) = wsd.Cells(i, 3)
trouvé = False
For j = 2 To dlp
If wsp.Cells(j, 5) <> 0 Then
If InStr(wsp.Cells(j, 4), Trim(wsd.Cells(i, 2))) <> 0 Then
wsp.Cells(j, 5) = wsp.Cells(j, 5) - 1
wsa.Cells(dla, 4) = "S3" & wsp.Cells(j, 1) & "T" & wsp.Cells(j, 2)
trouvé = True
Exit For
End If
End If
Next j
If trouvé Then
Else
wsa.Cells(dla, 4) = "Plus de place disponible"
End If
Next i
wsp.Columns("E:E").ClearContents
End Sub