June 30, 2020
I've added a date time picker to an Excel form to allow the user to choose a date rather than having to enter each time. When I first add the functionality only the date displays. When I close and open the file the field displays the date and time. How do I remove the time from the display?
October 5, 2010
Hi Christy,
If your file is too large to upload here then use OneDrive and share it.
That said, if you are using the code from here
https://www.myonlinetraininghu.....-userforms
it should already be just returning a date, no time component.
If you are getting a date.time returned then you can remove the time by using the INT or TRUNC functions before writing the value to the cell
https://www.myonlinetraininghu.....time-value
Regards
Phil
June 30, 2020
Phil, Thanks for the resources. One question, will these methods work for multiple cells in the workbook? Here is the code I set up to create a date picker in multiple cells in the workbook. Is it possible to add a line of code to ensure the date displays as a date only? It works when I first add the date picker to the cells but when I save the file and open it again, the cells display date and time.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
With Sheet1.DTPicker1
.Height = 20
.Width = 20
If Not Intersect(Target, Range("A:A")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Left = Target.Offset(0, 1).Left
.LinkedCell = Target.Address
Else
.Visible = False
End If
End With
With Sheet1.DTPicker2
.Height = 20
.Width = 20
If Not Intersect(Target, Range("I:I")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Left = Target.Offset(0, 1).Left
.LinkedCell = Target.Address
Else
.Visible = False
End If
End With
With Sheet1.DTPicker3
.Height = 20
.Width = 20
If Not Intersect(Target, Range("L:L")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Left = Target.Offset(0, 1).Left
.LinkedCell = Target.Address
Else
.Visible = False
End If
End With
With Sheet1.DTPicker4
.Height = 20
.Width = 20
If Not Intersect(Target, Range("S:V")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Left = Target.Offset(0, 1).Left
.LinkedCell = Target.Address
Else
.Visible = False
End If
End With
With Sheet1.DTPicker5
.Height = 20
.Width = 20
If Not Intersect(Target, Range("X:X")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Left = Target.Offset(0, 1).Left
.LinkedCell = Target.Address
Else
.Visible = False
End If
End With
With Sheet1.DTPicker6
.Height = 20
.Width = 20
If Not Intersect(Target, Range("O:O")) Is Nothing Then
.Visible = True
.Top = Target.Top
.Left = Target.Offset(0, 1).Left
.LinkedCell = Target.Address
Else
.Visible = False
End If
End With
End Sub
In the properties window the Format is set to 3-dtpCustom and the CustomFormat is set to mm/dd/yyyy. I have tried setting the format to 1-dtpShort Date as well with no impact after I save the file and open it again.
October 5, 2010
Hi Christy,
If you use the code I linked to it will solve your problems. I've incorporated it into the attached file.
Double click a cell in Col A to display the date picker. The date you pick is stored into the selected cell in Col A.
You'll find the event code in the Sheet1(Log) module. Add other ranges/columns to enable them to use the date picker too - hopefully the comments in the code make it clear what to do. If not just ask.
Regards
Phil
1 Guest(s)