Stuck on this!
Excel VBA
I need to fill a combobox with dates starting with (Date - 24months) to current (Date). the combo date display must be MMMM-YYYY
Is the loop below correct...I just need a counter to increment the months, but how do do the years...etc...
Code: Select all
Dim dtD As Date
dtD = DateSerial(Year(Date), Month(Date - 2), Day(1))
Do While dtD < Date
dtD = dtD + DateSerial(Year(dtD),Month(dtD)+1,Day(1))
Sheet2.cbo_ReturnMonth.AddItem (Format(dtD, "mmmm-yyyy"))
Loop