Hi,
I am creating a dynamic calendar and would like for the first of the month to show under the correct day of the week.
Here is my code:
Sub Show_Date()
Dim First_Date As Date
Dim Last_Date As Date
First_Date = VBA.CDate("1-" & Me.cmbMonth.Value & "-" & Me.cmbYear.Value)
Last_Date = VBA.DateSerial(Year(First_Date), Month(First_Date) + 1, 1) - 1
Dim i As Integer
Dim btn As MSForms.CommandButton
'=== to remove any caption from buttons
For i = 1 To 42
Set btn = Me.Controls("CommandButton" & i)
btn.Caption = ""
Next i
'=== set first date of the month
For i = 1 To 7
Set btn = Me.Controls("CommandButton" & i)
If VBA.Weekday(First_Date) = i Then
btn.Caption = "1"
End If
Next i
Have I missed something or written something incorrectly?
Thanks in advance.
Caz
I am creating a dynamic calendar and would like for the first of the month to show under the correct day of the week.
Here is my code:
Sub Show_Date()
Dim First_Date As Date
Dim Last_Date As Date
First_Date = VBA.CDate("1-" & Me.cmbMonth.Value & "-" & Me.cmbYear.Value)
Last_Date = VBA.DateSerial(Year(First_Date), Month(First_Date) + 1, 1) - 1
Dim i As Integer
Dim btn As MSForms.CommandButton
'=== to remove any caption from buttons
For i = 1 To 42
Set btn = Me.Controls("CommandButton" & i)
btn.Caption = ""
Next i
'=== set first date of the month
For i = 1 To 7
Set btn = Me.Controls("CommandButton" & i)
If VBA.Weekday(First_Date) = i Then
btn.Caption = "1"
End If
Next i
Have I missed something or written something incorrectly?
Thanks in advance.
Caz