+ Reply to Thread
Results 1 to 9 of 9

Thread: Adding date to cell with time through userform

  1. #1
    Registered User
    Join Date
    05-18-2008
    Posts
    54

    Adding date to cell with time through userform

    Hi All

    I have a Userform that has become quite complex. The problem I am having is this:

    Two of the elements of the form are a Start Time and Date. I need the form to accept the input as 06021400 ie mmddhhmm.

    Then for this to translate into the Excel Sheet to display just hh:mm.

    Is there any way I can do this. I have tried a multitude of things, the last being:

    "VariableName = Format(Date, "mmddhhmm")"

    however had no joy

    Please help if possible.

    Thanks

    Matt

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Adding date to cell with time through userform

    Hello Matt,

    When you say "Userform" Are you referring to a worksheet or a VBA UserForm?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    05-18-2008
    Posts
    54

    Re: Adding date to cell with time through userform

    Sorry, should have said that.

    VBA UserForm, which then puts the data into a worksheet

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Adding date to cell with time through userform

    Hello peakymatt,

    Assuming your initial value "06021400" was input using a text box, you can simply remove the hours and minutes portion using string functions like this...
    Dim myTime As String
    
      myTime = Right(TextBox1.Value, 4) 
    
     'Remove this line if you don't want the colon
      myTime = Left(myTime, 2) & ":" & Right(myTime, 2)     'myTime = "14:00"
    
      Range("A1").Value = myTime
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    05-18-2008
    Posts
    54

    Re: Adding date to cell with time through userform

    Hi thanks for that

    I must be doing something wrong. I have added the code to my UserForm

    and when I enter the value in the textbox and submit the form all I get back in the Spreadsheet is "#########.

    Any ideas??

  6. #6
    Registered User
    Join Date
    05-18-2008
    Posts
    54

    Re: Adding date to cell with time through userform

    Hi Further to my last

    Have got it to returna result, the entry detail was "02061900" the result was "10190000". Any ideas how I can get the output to be the same as the input, with the output tio display just as hh:mm.

    Thanks

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979

    Re: Adding date to cell with time through userform

    Hello peakymatt,

    I think I should have a look at your workbook. Can you post a copy for me?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  8. #8
    Registered User
    Join Date
    05-18-2008
    Posts
    54

    Re: Adding date to cell with time through userform

    The work is on a secure system, so can't actually send it. Will try and do up a dummy to replicate my problem.

    Stand by, and thanks again

  9. #9
    Registered User
    Join Date
    05-18-2008
    Posts
    54

    Re: Adding date to cell with time through userform

    Hi Again

    Here we go. This will give you an idea of what I am trying to achieve.

    Person ID in Col A, Start Time in Col B, Stop Time in Col C. Then as you can see there is a days worth of times across the top, set up in 30 min increments. When the times are entered from the Form they go into COL B and COL C, and then it is conditionally formatted over the time period. Dates for the times has to be current date, then when it clocks over midnight the date is obviously tomorrow.

    All data is on the sheet named timeline. Activate the form by the button towards the bottom

    Hopefully you can help

    Thanks
    Attached Files Attached Files

+ 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.2.0