Question : Calendar with current date and month

Hi Experts,

Im using the attached script for Calendar activation. How to code the Calendar to always indicate the current date and month? Please advice.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
Private Sub Calendar1_Click()
  Dim ShObj As Worksheet
  
  Set ShObj = ThisWorkbook.Worksheets("Detail Task")
  ShObj.Rows(7).Copy
  
  ShObj.Rows(ActiveCell.Row).Select
  ActiveCell.Insert shift:=xlDown
  ShObj.Cells(ActiveCell.Row, 2) = Calendar1.Value
  ShObj.Range(ShObj.Cells(ActiveCell.Row, 3), ShObj.Cells(ActiveCell.Row, 7)) = ""
  Application.CutCopyMode = False
  Unload Me
End Sub

Private Sub Calendar1_Initialize()
  If IsDate(ActiveCell.Value) Then
            Calendar1.Value = DateValue(ActiveCell.Value)
      Else
            Calendar1.Value = Date
      End If
End Sub

Answer : Calendar with current date and month

Maybe you should replace this:
Private Sub Calendar1_Initialize()
  If IsDate(ActiveCell.Value) Then
            Calendar1.Value = DateValue(ActiveCell.Value)
      Else
            Calendar1.Value = Date
      End If
End Sub

into your userform, so something like this:
Private Sub Userform_Initialize()
  If IsDate(ActiveCell.Value) Then
            Calendar1.Value = DateValue(ActiveCell.Value)
      Else
            Calendar1.Value = Date
      End If
End Sub

Or did you renamed your userform to calendar1?
Random Solutions  
 
programming4us programming4us