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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

920 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

16 Experts available now in Live!

Get 1:1 Help Now