+ Reply to Thread
Results 1 to 7 of 7

Prompt for Date/Time

  1. #1
    Forum Contributor
    Join Date
    04-02-2008
    Location
    Jacksonville Beach, Florida
    MS-Off Ver
    Microsoft Excel 2003 and 2010
    Posts
    264

    Prompt for Date/Time

    Looking for code that prompts a user to enter a date and time (eg 02/02/2011 8:31 PM) and then pastes that date/time into another cell (eg A1). I would like the user to be limited to the date/time format I provided for consistency and calculations.

    It would be even better if the code could default to the current date and time and then ask the user, "Do you want to use the current date/time?". They would then choose "Yes" or "No". If the answer is "Yes", the current date and time would be pasted in the aforementioned spot (cell A1). If the answer is "No", the user would have the option to type the current date and time and have that data input pasted to A1.

    Any help woul be greatly appreciated.
    Last edited by dreicer_Jarr; 02-02-2011 at 09:59 PM.
    ______________________________________
    "Vision without Execution is a Hallucination"
    Edison

  2. #2
    Forum Contributor
    Join Date
    04-02-2008
    Location
    Jacksonville Beach, Florida
    MS-Off Ver
    Microsoft Excel 2003 and 2010
    Posts
    264

    Re: Prompt for Date/Time

    Should I make this question more clear?

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Prompt for Date/Time

    Maybe like this:
    Please Login or Register  to view this content.
    Last edited by shg; 02-04-2011 at 02:16 PM. Reason: corrected to allow entry of 1- and 2-digit hours
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Contributor
    Join Date
    04-02-2008
    Location
    Jacksonville Beach, Florida
    MS-Off Ver
    Microsoft Excel 2003 and 2010
    Posts
    264

    Re: Prompt for Date/Time

    This works FANTASTIC, thank you. For the record (meaning other users), I adjusted the code very slightly to allow the entering of "two-digit hours" like 10, 11, and 12. Again, thanks so much and look for positive feedback.

    Sub dj()
    Dim sDate As String
    Dim v As Variant

    Do
    sDate = InputBox(Prompt:="Date & time?", _
    Default:=Format(Now, "mm/dd/yyyy hh:mm AM/PM"))
    If sDate Like "##/##/#### ##:## [aApP][mM]" Or _
    sDate Like "##/##/#### ##:## [aApP][mM]" Then
    v = DateValue(sDate)
    End If
    Loop While IsEmpty(v)

    Range("A1") = CDate(sDate)
    End Sub

  5. #5
    Valued Forum Contributor jwright650's Avatar
    Join Date
    12-10-2010
    Location
    Va, USA
    MS-Off Ver
    Excel 2003, Excel 2010
    Posts
    606

    Re: Prompt for Date/Time

    just a note:
    That inputbox forces you to choose a date/time, with no way to escape until that takes place....kinda scary not to be able to get out of the loop with a disabled "x" button and no cancel button.
    Life is like a roll of toilet paper. The closer it gets to the end, the faster it goes.
    John Wright

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Prompt for Date/Time

    dreicer, please edit your post to add CODE tags.

    I corrected the code below to support one- and two-digit hours

  7. #7
    Registered User
    Join Date
    02-16-2016
    Location
    USA
    MS-Off Ver
    365
    Posts
    4

    Re: Prompt for Date/Time

    Hi I am looking for something exactly as you describe but I have no Idea how to make it work (I'm a 98% NEWBIE),
    SORRY if my question seems so foolish..

    So where do I put the code on sheet1 or as a module
    and once I do that how do I make it work so that when the user get's to A1 the macro pops up..
    and what about if I need to do the same question in lets say A1:A1500
    My users have to enter a verification date and time for each customer like this:
    Date and Time Note
    03/01/2016 11:00 Called customer not interested
    03/01/2016 14:00 Customer call he will do it.

    I would appreciate if you can help..

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1