+ Reply to Thread
Results 1 to 4 of 4

Formatting numbers in a text box

  1. #1
    Registered User
    Join Date
    03-27-2006
    Posts
    70

    Formatting numbers in a text box

    In a cell I might have 15 or 15.5.

    In the text box that is NOT linked to the cell but gets it's value from it in the activate function, I want it to display 15.00% or 15.50%.

    I want the user to be able to change that number, and when they are done, it to show to two decimals and the "%" sign.

    Is there any direct formatting command, or am I going to "get" to go through all kinds of gyrations of switching it to string, adding or truncating charaters, displaying, checking for changes (if possible) and reformatting for display?

    Thank-you for all thoughts!
    Last edited by brucemc; 06-30-2006 at 06:31 PM. Reason: Turn subscription on.

  2. #2
    Norman Jones
    Guest

    Re: Formatting numbers in a text box

    Hi Bruce,

    Try:

    Me.TextBox1.Value = Format(Range("A1").Value / 100, "0.0%")


    ---
    Regards,
    Norman



    "brucemc" <[email protected]> wrote in
    message news:[email protected]...
    >
    > In a cell I might have 15 or 15.5.
    >
    > In the text box that is NOT linked to the cell but gets it's value from
    > it in the activate function, I want it to display 15.00% or 15.50%.
    >
    > I want the user to be able to change that number, and when they are
    > done, it to show to two decimals and the "%" sign.
    >
    > Is there any direct formatting command, or am I going to "get" to go
    > through all kinds of gyrations of switching it to string, adding or
    > truncating charaters, displaying, checking for changes (if possible)
    > and reformatting for display?
    >
    > Thank-you for all thoughts!
    >
    >
    > --
    > brucemc
    > ------------------------------------------------------------------------
    > brucemc's Profile:
    > http://www.excelforum.com/member.php...o&userid=32871
    > View this thread: http://www.excelforum.com/showthread...hreadid=557505
    >




  3. #3
    Registered User
    Join Date
    03-27-2006
    Posts
    70
    Seemed like we were on the right path, and still suspect so, but something awful weird is going on. You will notice in the following I have stuck in a number of extra steps in that I am trying to disect the problem:

    Please Login or Register  to view this content.
    What is happening is that at first the proper figure is displayed - let us say 17.00%, which is drawn from a cell formatted as % whose underlying value is .17, just in case that comes into play in the problem and I don't know it - I do find it strange though that instead of bringing in .17 as a number, it is bringing it over as a formattted string, and the formatted string is "17" (a whole number - not a decimal).

    Then when I change it over to 17.5 in the text box on the form a change event is again triggered and I get a type mismatch error. I checked out what Me.tb_r_11.Value is equal to, and more importantly it IS a string, being "17.50%", however and nonetheless, Excel is barfing it back to me claiming a mismatch this time when I try to get the Val of it, but it would not be running that section if it were not a string which is how it was run the first time when bringing it in from the cell, so what the heck???

  4. #4
    Registered User
    Join Date
    03-27-2006
    Posts
    70
    OK, my friends, I have "solved" the problem, I hope, for now, by throwing in an On Error Resume, but I seriously think I am either sticking a band-aid on my own error in coding that I just don't know enough to spot, or a stupid bug in Excel. Anyone able to help out on this one?

+ 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