Pop-Up Calendar Via VBA - Any Date Field

kescco

Board Regular
Joined
Sep 14, 2009
Messages
174
I am hoping someone can help on this. I have already created a calendar which can be used by clicking in a date field and then choosing Insert Date. I think a tutorial is on www.fontstuff.com.

What I am wondering is if there is a way for the calendar to pop-up any time a cell formatted as date is clicked on.

Thank You,

Kescco :cool:
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
  • Right-Click on the sheet tab you want this to work on
  • Select View Code from the pop-up menu
  • Paste the code below in the VBA edit window.
  • This assumes your Calendar macro is called OpenCalendar

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim str As String
    If Target.Cells.Count = 1 Then
        str = Target.NumberFormat
        If ((InStr(str, "d") > 0) + (InStr(str, "m") > 0) + (InStr(str, "yy") > 0)) < -1 Then
            Call [I]OpenCalendar[/I]
        End If
    End If
End Sub

If the date format is Day-only or Month-only or Year-only, then this needs to be modified. It should work for any other Date formats (I think).
 
Upvote 0
The macro works great!
As I'm using a french version, I have changed the date language to french and it's so cool.
Thank you very much
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,787
Members
452,942
Latest member
VijayNewtoExcel

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