User Form Time Picker

Posted on 2014-04-23
Last Modified: 2014-04-25
I've tweaked some code for a pop up time picker I found here:

I'd like to have the time picker "remember" the value in the cell if I double click on it. Currently, I can change the time and it stays in the cell but if double click the cell again, it defaults back to 8:00 AM. In other words, if I change the time to 7:00 AM and double click the same cell, I want it to say 7:00 AM.

I've attached an example file. Thank you.
Question by:tracyms
  • 3
LVL 48

Accepted Solution

Rgonzo1971 earned 300 total points
ID: 40019289

pls try

Private Sub UserForm_Initialize()
     FrmTime.txtFollowupTime1.Locked = True
     FrmTime.txtFollowupTime1.Value = Format(TimeValue(ActiveCell), "hh:mmAM/PM")
     init_disp = Trim(FrmTime.txtFollowupTime1.Value)
End Sub

Open in new window

LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 200 total points
ID: 40019970
You could use:
Private Sub UserForm_Initialize()
     With Me.txtFollowupTime1
        .Locked = True
        If Len(ActiveCell.Value) > 0 And IsDate(ActiveCell.Value) Then
            .Value = ActiveCell.Text
            .Value = Format(TimeSerial(8, 0, 0), "hh:mmAM/PM")
        End If
            init_disp = Trim(.Value)
    End With

End Sub

Open in new window

BTW, I think you want the Cancel = True in your BeforeDoubleClick code inside the If part rather than the Else part.

Author Comment

ID: 40023844
Thanks! Both worked so I will divide the points. On another note - I'd love to have the same thing for dates. I've attached a sample I found on the Internet and will open another question if you're interested in solving it.

Author Closing Comment

ID: 40023845
I gave the first posted solution extra points since he was first. I hope this seems fair to you both. Thanks again!

Author Comment

ID: 40023892

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now