Pop-up calander within a cell


Posted by Adams on October 22, 2001 6:12 AM

I have a cell range for a date and I'd like (when a user clicks on a cell) for a pop-up calender to appear. The user can select a date and the date will appear in the cell. Is there anyway to do this????
Thanks



Posted by Geoffrey Hurst on October 23, 2001 3:06 AM

In VBE go to Tools>References (or perhaps Tools>AdditionalControls) and find Calendar Control 9.0 if Excel 2000 (8.0 if Excel 97).
Put this control on a user form and add a command
button plus two spin buttons.

Put the following in the Sheet's code module (based on a date being required in A1 whenever A1 is selected):-

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$A$1" Then UserForm1.Show
End Sub

Put the following in the Form's code module :-

Private Sub CommandButton1_Click()
ActiveSheet.Range("A1") = Calendar1.Value
Me.Hide
End Sub

Private Sub SpinButton1_Change()
'MsgBox SpinButton1.Value
If Calendar1.Month = 12 And SpinButton1.Value > 0 Then
Calendar1.Year = Calendar1.Year + 1
Calendar1.Month = 1
ElseIf Calendar1.Month = 1 And SpinButton1.Value < 0 Then
Calendar1.Year = Calendar1.Year - 1
Calendar1.Month = 12
Else
Calendar1.Month = Calendar1.Month + SpinButton1.Value
End If
SpinButton1.Value = 0
End Sub

Private Sub SpinButton2_Change()
Calendar1.Year = Calendar1.Year + SpinButton2.Value
SpinButton2.Value = 0
End Sub