+ Reply to Thread
Results 1 to 14 of 14

Format number as time ("h:nn") within a textbox

  1. #1
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Format number as time ("h:nn") within a textbox

    Hi there, I am trying to format a textbox value which shows as a number in a textbox as time i.e. 0.5 will show as 12:00. Any ideas?

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: Format number as time ("h:nn") within a textbox

    Maybe something like textbox('xyz").value = format(0.5, "hh:mm")?

  3. #3
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Format number as time ("h:nn") within a textbox

    The value won't always be 0.5. It will change.

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

    Re: Format number as time ("h:nn") within a textbox

    Change 0.5 to textboxname.Value

    For example.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Format number as time ("h:nn") within a textbox

    Just tried that but unfortunately it does not work. No error message though. This is the code I used:-

    Please Login or Register  to view this content.

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

    Re: Format number as time ("h:nn") within a textbox

    Does Reg11.Value have a value in it?

  7. #7
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Format number as time ("h:nn") within a textbox

    yes it does 0.5. Tried the code by attaching it to a different event and it worked. It just does not work on the Userform_intialize() event?
    Last edited by forrestgump1980; 03-23-2015 at 12:14 PM.

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

    Re: Format number as time ("h:nn") within a textbox

    How/when is the textbox being populated with 0.5?

    What events did you try?

  9. #9
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Format number as time ("h:nn") within a textbox

    the text box is populated with 0.5 when opening the userform as it is linked to a cell in excel. When I attached the code to another button it worked, but it still won't work on Userform_intialize() event.

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

    Re: Format number as time ("h:nn") within a textbox

    Is the cell it's linked to formatted as hh:mm?

  11. #11
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Format number as time ("h:nn") within a textbox

    yes it is as well

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

    Re: Format number as time ("h:nn") within a textbox

    If you want a value on a spreadsheet to appear in a textbox as it's formatted on the sheet remove the cell link and add this to the Initialize event, change Sheets("Sheet1").Range("A10") to the relevant sheet and cell.
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    180

    Re: Format number as time ("h:nn") within a textbox

    Thanks for your help with this. I think you have got me going in the right direction and I think it is because sometimes i refer to the value as .value and sometimes .text. I will experiment a little more tonight and let you know how I get on. Thanks once again.

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

    Re: Format number as time ("h:nn") within a textbox

    I think the problem you are encountering might have something to do with the textbox being linked to a cell.

    When you do that it's the underlying value in the cell that will appear in the textbox.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Geting headick to Format(Now, "dd.mm.yyyy hh:mm") inside a userform textbox!
    By Reemet in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-11-2014, 10:29 AM
  2. [SOLVED] inputting a number representing "Time" spent on a "Task" under drop menu's
    By cubbymonkey in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-09-2014, 04:03 PM
  3. Replies: 2
    Last Post: 11-01-2012, 04:35 PM
  4. Textbox Lost Functionality - '=EMBED("Forms.TextBox.1","")' missing
    By JoeByrne in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2010, 05:41 AM
  5. Extract "Time" from custom "Date and Time" format
    By ben_patto in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-24-2009, 08:47 PM

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