Last active
January 23, 2017 05:55
-
-
Save theTonyHo/a22bbe6db5525f897d9d7149ad6c9f73 to your computer and use it in GitHub Desktop.
Generic Date Picker in Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' Insert Microsoft Date and Time Picker control in the document and paste the following code on the sheet. | |
' Reference: http://www.techrepublic.com/blog/microsoft-office/how-to-acquire-position-and-hide-a-calendar-control-in-an-excel-sheet/ | |
Private Sub DTPicker1_Change() | |
' Set picked date to active Cell. | |
ActiveCell.Value = Me.DTPicker1.Value | |
End Sub | |
Private Sub Worksheet_SelectionChange(ByVal Target As Range) | |
' Anchor control to the active cell. | |
' Display control only when active cell contains a date. | |
If IsDate(ActiveCell.Value) Or ActiveCell.Value = "dd/mm/yyyy" Then | |
With DTPicker1 | |
.Visible = True | |
.Left = ActiveCell.Left | |
.Top = ActiveCell.Top | |
.Width = ActiveCell.Width | |
.Height = ActiveCell.Height | |
End With | |
Else | |
DTPicker1.Visible = False | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment