Citation :
Sub D_DatesDebutMsn2() Dim i As Integer Application.ScreenUpdating = False Worksheets("Feuil3" ).Range("A:B" ).ClearContents Worksheets("data" ).Columns("D:G" ).NumberFormat = "General" LastRow = Worksheets("data" ).Cells(65536, 2).End(xlUp).Row Dim vMsn As Variant Dim dico As New Scripting.Dictionary Dim temp As String Dim Last_date As Date Dim Last_objet As String With ThisWorkbook.Worksheets("data" ) For i = 2 To LastRow If StrComp(.Cells(i, 8).Value, "Oui", vbTextCompare) = 0 And .Cells(i, 6).Value > 0 Then 'date la + ancienne pour chaque objet If dico.Exists(CStr(Worksheets("data" ).Cells(i, 2).Value)) = False Then 'on ajoute dnas le dico l'objet inexistant dico(CStr(Worksheets("data" ).Cells(i, 2).Value)) = CStr(Format(.Cells(i, 6).Value, "yyyymmdd" )) Else 'on compare la nouvelle date et celle dans le dico If Val(CStr(Format(.Cells(i, 6).Value, "yyyymmdd" ))) < Val(dico(CStr(Worksheets("data" ).Cells(i, 2).Value))) Then 'on change la date pour la + recente dans le dico dico(CStr(Worksheets("data" ).Cells(i, 2).Value)) = CStr(Format(.Cells(i, 6).Value, "yyyymmdd" )) End If End If If CDate(.Cells(i, 6)) > Last_date Then Last_date = CDate(.Cells(i, 6)) Last_objet = .Cells(i, 2).Value End If End If Next i End With Worksheets("data" ).Columns("D:G" ).NumberFormat = "m/d/yyyy" With Worksheets("Feuil3" ) 'extraction du resultat i = 1 For Each vMsn In dico.Keys .Cells(i, 1).Value = vMsn temp = dico(vMsn) .Cells(i, 2).Value = CDate(DateSerial(Left(temp, 4), Mid(temp, 5, 2), Right(temp, 2))) i = i + 1 Next vMsn Set dico = Nothing Application.ScreenUpdating = True End With End Sub
|