+ Reply to Thread
Results 1 to 8 of 8

Time not displaying correctly in textbox on a userform

  1. #1
    Registered User
    Join Date
    12-04-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Time not displaying correctly in textbox on a userform

    Hi,

    the problem I am having is shown by the following example.

    Cell A1 is formatted "mm:ss.00" and has the value 1:45.26 entered (note that the formula bar displays this as 12:01:45 AM).

    I have a userform with a textbox and the following code is entered in the forms initialize event

    Please Login or Register  to view this content.
    When the form is opened the value displays as "12:45.00" whereas I was expecting (and wanting) "1:45.26"

    Cheers

    Jeff

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Time not displaying correctly in textbox on a userform

    if you aren't including hours you have to use "nn:ss.00" as the format code
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Valued Forum Contributor
    Join Date
    11-15-2008
    Location
    ph
    MS-Off Ver
    2007/2010/2016
    Posts
    479

    Re: Time not displaying correctly in textbox on a userform

    Hi -

    Try
    Please Login or Register  to view this content.
    Regards,
    Event

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Time not displaying correctly in textbox on a userform

    You don't need to use Format, the Text property will return the value in the cell as it's formatted.

  6. #6
    Registered User
    Join Date
    12-04-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Time not displaying correctly in textbox on a userform

    Thanks for all of your responses.

    Norie and Event, both of your suggestions gave a good results. Joseph, your suggestion improved the result but it rounds the value to the nearest second, ie, "1:45.00" instead of "1:45.26"

    Cheers

    Jeff

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Time not displaying correctly in textbox on a userform

    Jeff

    What I suggested should give you the value exactly as it's formatted on the worksheet.

    Did that not happen?

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Time not displaying correctly in textbox on a userform

    I think Jeff already said it did work-and he marked it solved?

    if you don't want to use .Text (which can get slow if you use it a lot) you can use
    Please Login or Register  to view this content.

+ 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