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
| Sub TroisMois()
Dim Col As Integer, Lig As Long, Num As Long
Dim DateFin As Long, NbMois As Integer
Dim DT As Long
'------------------------------------------------
'Pour l'exemple
Col = 4 'colonne D
Lig = 3 'ligne où se trouve la date de départ.
'Dans la cellule D3 la date de départ.
'Dans la cellule E3 le nombre de mois (3)
'Dans la cellule F3 le nombre d'année (5)
'------------------------------------------------
With Sheets("Feuil1") 'adapter le nom de la feuille
NbMois = .Cells(Lig, Col + 1)
DateFin = DateSerial(Year(.Cells(Lig, Col)) + .Cells(Lig, Col + 2), Month(.Cells(Lig, Col)), Day(.Cells(Lig, Col)))
DT = DateSerial(Year(.Cells(Lig, Col)), Month(.Cells(Lig, Col)) + NbMois, Day(.Cells(Lig, Col)))
While DT < DateFin
Lig = Lig + 1: Num = Num + 1
.Cells(Lig, Col - 2) = Num
.Cells(Lig, Col - 1) = CDate(DT)
DT = DateSerial(Year(DT), Month(DT) + NbMois, Day(DT))
Wend
.Cells(Lig, Col - 2) = "maturité"
.Cells(Lig, Col - 1) = CDate(DT)
End With
End Sub |
Partager