How to close Calendar Control using the ESC key

jamesperrin1976

New Member
Joined
Feb 8, 2009
Messages
13
Please can someone help me?

I have found some code on the internet to open the calendar control when the operator clicks on an unlocked cell in my spreadsheet (see the code below).

My problem is that I want the calendar to close if the operator hits the ESC key or (if possible) starts writing in the cell instead of selecting a date from the calendar. Does anyone know how to do this? I have seen a method using a userform but I want the calendar to appear without a titlebar.

Thanks in advance,
James

Code:
Private Sub Calendar1_Click()
    ActiveCell.Value = CDbl(Calendar1.Value)
    ActiveCell.NumberFormat = "dd-mmm-yy"
    ActiveCell.Select
    Calendar1.Visible = False
End Sub


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If ActiveCell.Locked = False Then
        With Calendar1
            .Visible = True
            .Left = Target.Left
            .Top = Target.Top + Target.Height
        End With
        If IsDate(ActiveCell.Value) Then
            Calendar1.Value = ActiveCell.Value
        Else
            Calendar1.Value = Date
        End If
    Else
        Calendar1.Visible = False
    End If
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Forum statistics

Threads
1,214,965
Messages
6,122,495
Members
449,088
Latest member
Melvetica

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top