+ Reply to Thread
Results 1 to 6 of 6

VBA - Decimals Automatically convert to Natural Numbers - Help!

  1. #1
    Registered User
    Join Date
    08-14-2012
    Location
    Hamburg, Germany
    MS-Off Ver
    Excel 2010
    Posts
    5

    Unhappy VBA - Decimals Automatically convert to Natural Numbers - Help!

    Hi all!

    I have a few textboxes which get their values (numbers with decimals using commas) from an excel table. Now I want to do calculations with these numbers, e.g "1 - textbox1.value" with 0,8 being the textbox's value from the Excel sheet. Note: The textbox displays "0.8" though, if that matters.

    Then, instead of displaying "0,2" (or "0.2" for that matter), I get "-7". How can I change that? VBA somehow transforms "0,8" to "0.8" to "8".

    When adding the data to the Excel sheet I always use CDbl().

    And I tried the following code:

    Please Login or Register  to view this content.
    Thank you!!
    Last edited by Cutter; 08-14-2012 at 01:25 PM. Reason: Added code tags

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

    Re: VBA - Decimals Automatically convert to Natural Numbers - Help!

    how do you load the value into the textbox in the first place? the issue is that in your regional settings 0.8 is 8 since your decimal separator is a comma
    Josie

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

  3. #3
    Registered User
    Join Date
    08-14-2012
    Location
    Hamburg, Germany
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: VBA - Decimals Automatically convert to Natural Numbers - Help!

    Well, in Excel I have 0,8 and I just say textbox1.value=Cells(1,1).value whcih leaves me with textbox1.value being 0.8 . But somehow that seems to become 8...

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

    Re: VBA - Decimals Automatically convert to Natural Numbers - Help!

    I reckon it's a bug-xl2013 does not behave the same way. try using
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-14-2012
    Location
    Hamburg, Germany
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: VBA - Decimals Automatically convert to Natural Numbers - Help!

    Thanks, that works! You're probably right, it's gotta be a bug.

    In the meantime I tried something else that works as well: I replace all commas in the textboxes after they are entered using the following code.


    Please Login or Register  to view this content.

    The idea how to do this I got from another thread in this forum. Both work but since I have multiple text boxes, this is easier to insert.

    ---------- Post added at 12:07 PM ---------- Previous post was at 12:05 PM ----------

    I don't know how to enter code the proper way, so sorry for the bad formatting..
    Last edited by Cutter; 08-14-2012 at 01:26 PM. Reason: Added code tags

  6. #6
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: VBA - Decimals Automatically convert to Natural Numbers - Help!

    @ Helen123

    Welcome to the forum.

    Please notice that code tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at top of the page and read Rule #3.
    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