M.Ustun
M.Ustun

Reputation: 289

Incrementing dates in Excel VBA

this is my current code:

For z = 3 To 52
    Cells(z, 1) = Cells((z - 1), 3) + 7
Next z      

Where cell z-1 is a date

I want to add 7 days to the previous cell however it's throwing an error, it this the right way to approach this issue or is there a simpler method?

Thank you

Upvotes: 0

Views: 1102

Answers (1)

Shai Rado
Shai Rado

Reputation: 33682

Try the DateAdd function, use inside the loop:

Cells(Z, 1) = DateAdd("ww", 1, Cells((Z - 1), 3))

Note: the 1st parameter, is the Interval, set it to "ww", which means weeks.

To read more about this function go to MSDN

Upvotes: 4

Related Questions