+ Reply to Thread
Results 1 to 6 of 6

Display Decimal value in text box ?

  1. #1
    Registered User
    Join Date
    03-11-2010
    Location
    SINGAPORE
    MS-Off Ver
    Excel 2007
    Posts
    12

    Lightbulb Display Decimal value in text box ?

    Hi,
    i am pretty new in VBA, and i am blocked in my program while i attempt to display a

    decimal value in a text box.

    For instance :

    i have a spreadsheet showing the percentage of completion of cables installation. I want to

    COUNT how many cables have been 100% pulled.

    Then i divide this value by the total of cable to get the % of total cable pulled for the

    project.

    When this value ( CablesPulled) is divided with a number giving a 0.xxxx value, the result

    is always 0 in the text box.

    If for instance, i divide by six, it shows the integer number, not decimal value.

    844 / 6 = 140 ( instead of 140.66) 844/1200 = 0 ( instead of 0.70)

    I think i have to format the text box value but i am not sure how.

    I tried different resources ( excel help, books...) but i can hardly find something treating

    this problem .

    This is a portion of my code :

    Please Login or Register  to view this content.

    Thanks all for your expertise.
    Last edited by Breizh29; 03-13-2010 at 05:50 AM.

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Display Decimal value in text box ?

    You are referencing the wrong variable. Don't use "CablesPulled", use "Total"

    Please Login or Register  to view this content.
    Last edited by Palmetto; 03-12-2010 at 08:58 AM.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  3. #3
    Registered User
    Join Date
    03-11-2010
    Location
    SINGAPORE
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Display Decimal value in text box ?

    Quote Originally Posted by Palmetto View Post
    You are referencing the wrong variable. Don't use "CablesPulled", use "Total"

    Please Login or Register  to view this content.
    Thanks for your help,
    however it still does not work. I have now the calculation working and display the decimal (.00) but only if the result is > 0. e.g 432.00, 23.00....
    If the result is <0 the display is 0.00.
    I try declaring both variables as Single but same effect.
    Here is the new code:

    Please Login or Register  to view this content.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Display Decimal value in text box ?

    Try using type Double, without converting to sub-type Decimal.
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    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: Display Decimal value in text box ?

    Hello Breizh29,

    Welcome to the Forum!

    There are a couple of problems here. First, you used integer division instead of floating point. the backslash "\" is used in VBA to divide and return an integer result. Probably a typo. You need to use a forward slash "/" for floating point division. Second, you do not need to convert to a decimal type. Third your conversion to a percentage needs to be multiplied by 100. This can be done in the Format statement using a percent sign. Here is the corrected code.
    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!)

  6. #6
    Registered User
    Join Date
    03-11-2010
    Location
    SINGAPORE
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Display Decimal value in text box ?

    Thanks to All and particulary to Leith for his straight answer.
    What is good here , is that i learn everyday.

+ 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