PDA

View Full Version : Creating dates



wakwak1
01-11-2008, 11:48 PM
If I start from some date, say 20070420 (in the yyyymmdd format), how can I get VBA to then fill down the column all following dates (so up to the present, 20080112) , such that all the months have the correct days etc. up to the present ?

Thanks!!

Bob Phillips
01-12-2008, 01:58 AM
Public Sub ProcessData()
Dim i As Long
Dim StartDate As Date

With ActiveSheet

StartDate = DateSerial(Left$(.Range("A1").Value, 4), _
Mid$(.Range("A1").Value, 5, 2), _
Right$(.Range("A1").Value, 2)) - 1
For i = 2 To 591

.Cells(i, "A").Value = Format(StartDate + i, "yyyymmdd")
Next i
End With

End Sub