1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| Function TrouveDate(Nom As Range, Plage As Range) As Date
Dim C As Range, ResDate As Date
Application.Volatile
Application.EnableEvents = False
'/// ajout et modif
Dim LigDeb&
Dim LigFin&
LigDeb& = Plage.Cells(1, 1).Row
LigFin& = LigDeb& + Plage.Rows.Count - 1
For i = LigFin& To LigDeb& Step -1
'///
''' For i = Cells(Rows.Count, Plage.Column).End(xlUp).Row To Plage.Row Step -1
Debug.Print Cells(i, Plage.Column).Value
If Application.CountIf(Plage, Nom) = 1 And Cells(i, Plage.Column).Value = Nom Then
TrouveDate = Cells(i, Plage.Column).Offset(, 1).Value
Exit Function
End If
If Cells(i, Plage.Column).Value <> Cells(i - 1, Plage.Column).Value Or _
Cells(i, Plage.Column).Offset(, 1).Value <> Cells(i - 1, Plage.Column).Offset(, 1).Value Or _
Cells(i, Plage.Column).Offset(, 2).Value <> Cells(i - 1, Plage.Column).Offset(, 2).Value Then
If Cells(i, Plage.Column).Value = Nom Then
If Cells(i - 1, Plage.Column) = Nom Then
If Cells(i - 1, Plage.Column).Offset(, 2) + 1 = Cells(i, Plage.Column).Offset(, 1) Then
ResDate = Cells(i - 1, Plage.Column).Offset(, 1)
ElseIf ResDate = 0 Then
TrouveDate = Cells(i, Plage.Column).Offset(, 1).Value
Exit Function
Else
TrouveDate = Cells(i, Plage.Column).Offset(, 1).Value
Exit Function
End If
End If
End If
End If
Next i
TrouveDate = ResDate
Application.EnableEvents = True
End Function |
Partager