+ Reply to Thread
Results 1 to 5 of 5

Text Box number format with Control Source

  1. #1
    Registered User
    Join Date
    09-24-2009
    Location
    Atkinson, NH
    MS-Off Ver
    Excel 2003
    Posts
    23

    Text Box number format with Control Source

    I have created a User Form with about 60 Text Boxes. The text boxes are all linked to Control Source cells in a sheet of my workbook. Changing the number in the text box changes the number in the control source cell and vice versa. Some of the text boxes take inputs from the user. Other text boxes display calculated results in the User Form. I don't like the format of the numbers in the text boxes for which the displayed results are calculated. In some cases, way too many significant digits are displayed (e.g., 0.0099999999 instead of 0.0100 or 600.6784536 instead of 600.68 or 0.0000003614564 instead of 3.61E-07). When the text box is NOT linked to a control source cell, I can format the number by code suce as TextBox1 = Format(Expression, "0.00E+00"). But when the text box is linked to the control source cell, it ignores the format code. How can I specify the number format of a text box that is likned to a control source cell? Thanks.

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

    Re: Text Box number format with Control Source

    Hello McNultyK,

    Here is an example using TextBox1. Change TextBox1 to match you control's name.
    Please Login or Register  to view this content.
    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
    09-24-2009
    Location
    Atkinson, NH
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Text Box number format with Control Source

    Thanks, Leith. The code you provided worked fine. It sets the text box number format the same as the control source format. You don't know how many hours I wasted trying to figure this out. Two questions:
    1. What resource materials could I have consulted to find this answer? I didn't find anything on this in the MS help files.
    2. Is there a simple way to set a general number format that most text boxes would use or is it necessary to write a private sub for each text box?

    Thanks again,
    Ken McNulty

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

    Re: Text Box number format with Control Source

    Hello Ken,

    Question 1. What resource materials could I have consulted to find this answer? I didn't find anything on this in the MS help files.

    Answer 1. Using the web is best resource. I have learned these obscure techniques by writing code for many years. The MS help files will only cover the very basics of the object model. The rest is basically learned from others, books, trial and error.

    Question 2. Is there a simple way to set a general number format that most text boxes would use or is it necessary to write a private sub for each text box?

    Answer 2. Each control has to be formatted separately, if you want a display format other than a basic string in the Text Box. Because these are ActiveX Controls (event driven), the format statement will have to be called from or added to an event. There is no general property to format a Text Box a certain way.

  5. #5
    Registered User
    Join Date
    09-24-2009
    Location
    Atkinson, NH
    MS-Off Ver
    Excel 2003
    Posts
    23

    Re: Text Box number format with Control Source

    SOLVED. (Many Thanks)

+ 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