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
| Sub AujourdhuiMoinsLaDate()
Set f = ActiveSheet 'ou Worksheets("Feuil1")
f.Select
dernligne = f.Cells(Rows.Count, 1).End(xlUp).Row
Set rg = f.Cells.Find(what:="*", After:=f.Cells(1, 1), LookIn:=xlValues, LookAt:=xlPart, SearchFormat:=False, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
If Not rg Is Nothing Then
dernColonne = rg.Column
Else
MsgBox "Il y a un probleme"
Exit Sub
End If
Set r = f.Range(f.Cells(1, dernColonne + 1), f.Cells(dernligne, dernColonne + 1))
r.Select
r.NumberFormat = "General"
Set premier = r.Cells(1, 1)
premier.Select
Set ref2 = premier.Offset(, -1)
ref2.Select
addr2 = ref2.Address(RowAbsolute:=False, columnabsolute:=False)
Set ref1 = ref2.Offset(, -1)
ref1.Select
addr1 = ref1.Address(RowAbsolute:=False, columnabsolute:=False)
'Formule à générer =DATEDIF(H4;I4;"y")
formule = "=DATEDIF(" & addr1 & ";" & addr2 & ";" & """y""" & ")"
premier.FormulaLocal = formule
premier.AutoFill Destination:=r, Type:=xlFillDefault
r.Select
Stop
r.FormulaLocal = r.Value 'Remplace les formules par les valeurs
End Sub |
Partager