Forum

Notifications
Clear all

Date Time Picker

10 Posts
2 Users
0 Reactions
182 Views
(@christy)
Posts: 8
Active Member
Topic starter
 

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?

 
Posted : 19/08/2020 2:32 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Christy,

Can't help you without your workbook, please attach it.

Phil

 
Posted : 19/08/2020 6:44 pm
(@christy)
Posts: 8
Active Member
Topic starter
 

Phil, The spreadsheet is attached. I'm working in Excel 2010. Thanks

 
Posted : 20/08/2020 8:10 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Christy,

Something went wrong with that upload because the link doesn't work.  Can you try again please.

Phil

 
Posted : 25/08/2020 9:56 pm
(@christy)
Posts: 8
Active Member
Topic starter
 

Phil, I've attached the file again. Hope it works this time.

 
Posted : 26/08/2020 11:41 am
(@christy)
Posts: 8
Active Member
Topic starter
 

I'm going to attach again, not sure why this isn't working properly.

 
Posted : 26/08/2020 11:45 am
(@christy)
Posts: 8
Active Member
Topic starter
 

Phil, I keep getting an error message that the file is too large but it didn't happen this last time. Hope third times the charm. ThanksLaugh

 
Posted : 26/08/2020 11:47 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

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.myonlinetraininghub.com/excel-calendar-date-picker-for-worksheets-and-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.myonlinetraininghub.com/extracting-date-and-time-from-a-datetime-value

Regards

Phil

 
Posted : 26/08/2020 7:02 pm
(@christy)
Posts: 8
Active Member
Topic starter
 

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.

 
Posted : 27/08/2020 9:46 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

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

 
Posted : 28/08/2020 12:55 am
Share: