List all dates between two dates in VBA

Hello friends! Today we’ll be learning to generate all the dates between two dates in VBA(as shown in image below).

Use the reusable code below

Sub generateDates()
'---Clearing the Range
Worksheets("Sheet1").Range("E2:E10000").Clear
'---Starting with the start date
Worksheets("Sheet1").Range("E2") = Worksheets("Sheet1").Range("B1")
'---Calculating the number of days between the start date and end date
Days = Int((Worksheets("Sheet1").Range("B2") - Worksheets("Sheet1").Range("B1")))
'---Generating the dates in cell E2
i = 2
Do
i = i + 1
Worksheets("Sheet1").Cells(i, 5) = Worksheets("Sheet1").Cells(i - 1, 5) + 1
Loop While i < 2 + Days
End Sub

Keep visiting Analytics Tuts for more tutorials.

Thanks for reading! Comment your suggestions and queries


Leave a Reply

Your email address will not be published. Required fields are marked *