Private Sub CommandButton2_Click()
Dim nom As Integer, tachesNouvelles As Integer, tacheAncienne As Range
Dim colTache As Range, ligneNom As Range, estCapable As Integer
ti = Timer
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim DerCol As Long, DerNom As Long
' Trouver la dernière colonne remplie
DerCol = Cells(9, Columns.Count).End(xlToLeft).Column
' Trouver la dernière ligne en partant du haut : CTRL+Flêche bas
DerNom = Range("D9").End(xlDown).Row
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For nom = 26 To DerNom
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For tachesNouvelles = 6 To DerCol
estCapable = 1
estPartiellementCapable = 0
Set tacheAncienne = Sheets("Nouveau").Cells(10, tachesNouvelles)
With Sheets("Dist")
While tacheAncienne.Row < 17
If tacheAncienne.Value <> vbNullString Then
Set colTache = .Rows(9).Find(What:=tacheAncienne.Value, LookIn:=xlValues, LookAt:=xlWhole) 'le "9" est le numéro de la ligne contenant les services'
Set ligneNom = .Columns(4).Find(What:=Sheets("Nouveau").Range("D" & nom).Value, LookIn:=xlValues, LookAt:=xlWhole) 'La colonne "4" est la colonne contenant les noms'
If ligneNom Is Nothing Then
estCapable = 0
Else
If Not colTache Is Nothing Then
estCapable = estCapable * IIf(.Cells(ligneNom.Row, colTache.Column).Value = 1, 1, 0)
estPartiellementCapable = estPartiellementCapable + IIf(.Cells(ligneNom.Row, colTache.Column).Value = 1, 1, 0)
End If
End If
End If
Set tacheAncienne = tacheAncienne.Offset(1, 0)
Wend
End With
If Sheets("Nouveau").Cells(10, tachesNouvelles).Value = vbNullString Then estCapable = 0 'le chiffre/nombre après ".Cells(" est à modifier suivant la 1ère ligne contenant les anciennes tâches comprises dans les nouveaux services'
Sheets("Nouveau").Cells(nom, tachesNouvelles).Value = IIf(estCapable = 1, 1, IIf(estPartiellementCapable > 0, 2, ""))
Next tachesNouvelles
Next nom
MsgBox "Mix des données terminé! Merci pour votre patience." & vbLf & vbLf & "Durée: " & Format(Timer - ti, "0.00\ sec.")
Application.Calculation = xlCalculationAutomatic 'Exit Sub
End Sub