Sub date_debut_fin()
Dim i As Integer, dl As Integer
Dim tmpstr() As String
Dim Dat1 As Date
Dim Dat2 As Date
Dim nbr_jr As Integer
Dim cellule As Range
Dim madate As String
Workbooks("fichier_client").Activate
Worksheets("Données brutes").Activate
dl = Range("E" & Rows.Count).End(xlUp).Row
For i = 2 To dl
valeur = Cells(i, 5).Value
tmpstr = Split(valeur, " ")
Range("F" & i) = CDate(tmpstr(0) & " " & tmpstr(1) & " " & tmpstr(2))
Range("F" & i).NumberFormat = "dd/mm/yyyy"
Next i
With Sheets("Analyse")
.Range("J2") = Application.Min(Range("F2:F" & dl))
.Range("J3") = Application.Max(Range("F2:F" & dl))
End With
With Sheets("Animation")
.Range("J2") = Application.Min(Range("F2:F" & dl))
.Range("J3") = Application.Max(Range("F2:F" & dl))
End With
Worksheets("Animation").Activate
For Each cellule In Range("J2:J3")
cellule.NumberFormat = "dd/mm/yyyy;@"
Next cellule
Worksheets("Analyse").Activate
For Each cellule In Range("J2:J3")
cellule.NumberFormat = "dd/mm/yyyy;@"
Next cellule
For Each cellule In Range("J2:J3")
cellule.NumberFormat = "dd/mm/yyyy;@"
Next cellule
'For Each cellule In Range("B2:B18")
'cellule.NumberFormat = "dd/mm/yy;@"
'Next cellule
Dat1 = Range("J2")
Dat2 = Range("J3")
nbr_jr = Dat2 - Dat1
Range("I20") = nbr_jr
Range("I20").Font.ColorIndex = 2
Range("I20").Font.Bold = True
Range("I20").Select
With Selection.Font
.Size = 14
End With
With Cells(20, 9)
.HorizontalAlignment = xlHAlignCenter
End With
With Cells(2, 10)
.HorizontalAlignment = xlHAlignRight
End With
With Cells(3, 10)
.HorizontalAlignment = xlHAlignRight
End With
End Sub
En gros je recupère la colonne E qui a la forme par exemple "14 juillet 2018 à 17:58" je recupere le texte "14 juillet 2018" puis je le transforme en date dans la colonne F juste à côté puis dans cette colonne je regarde quelle date est la plus loin est la plus proche