WaterRulesEverything
New Member
- Joined
- Nov 29, 2021
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Attempting to loop though dates using VBA but I'm getting an infinite loop. Cell A1 is the start date, cell A2 is the date incremented by 14 days, cell B2 is the stop date. I just want the dates to loop and increment by 14 days and stop when the date reaches cell B2. The incremented dates will continue to update in cells A1 and A2.
This code below increments the date fine, but I am getting an infinite loop where the code will continue to run past the set date in cell B2
1/26/2021 | |
2/8/2021 | 8/20/21 |
This code below increments the date fine, but I am getting an infinite loop where the code will continue to run past the set date in cell B2
VBA Code:
Sub Button1_Click()
Application.ScreenUpdating = True
StartDate = Range("A2").Value
EndDate = Range("B2").Value
'Do Until Range("A2").Value = Range("B2").Value
Do While StartDate < EndDate
Range("A1").Value = DateAdd("d", 1, CDate(Range("A2")))
Range("A2").Value = DateAdd("d", 14, CDate(Range("A2")))
Loop
End Sub