I want to be able to set two dates in excel and then select a drop down box for either "weekly" or "monthly". Then I would like to be able to press a button to run a macro that will fill an excel sheet with every date either weekly or monthly.
I am able to currently generate every date between two dates, but would like to be able to change this depending on a drop down box in excel.
I am able to currently generate every date between two dates, but would like to be able to change this depending on a drop down box in excel.
VBA Code:
Sub WriteDates()
'
Dim sc As Range
Dim Stdt As Date
Dim Edt As Date
Dim dDate As Date
Dim off As Integer
'
Stdt = Range("B3") ' start date
Edt = Range("B4") ' end date
Set sc = Range("A8") ' start cell
'
Range("A8").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.ClearContents
'
off = 0
'
For dDate = Stdt To Edt
If Format(dDate, "dd") = "01" Then
sc.Offset(0, off) = Format(dDate, "mmmm yyyy")
off = off + 1
End If
Next dDate
'
sc.Resize(off, 1).NumberFormat = "mmmm yyyy"
'
End Sub