+ Reply to Thread
Results 1 to 6 of 6

adding half value?

  1. #1
    Registered User
    Join Date
    12-17-2012
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    57

    adding half value?

    Hey all,

    I'm sure it's a silly thing I'm missing and I've done some research, but can't seem to find the right answer. My simple code copies the value from previously specified cell, then should add a value of 0,5 and copy back the final sum into the original cell. ie. cell C1 was 1, that 1 is copied to cell X100, 0,5 is added to 1 (so now cell X100 is 1,5) and that value is copied back to C1.

    The code:

    Please Login or Register  to view this content.
    In the above code, if I change 0.5 to 1 - it all works just fine. But VBA just won't add 0,5 to 0,5... What am I missing?

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: adding half value?

    I may have missed an important bit but, cant all that be reduced to:

    Please Login or Register  to view this content.
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    12-17-2012
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    57

    Re: adding half value?

    The issue here is that when a cell has already a value of 0,5, the vba code that should add 0.5 (resulting in 1 as a cell value) does not do that.

    Regardless of whether my code could be compressed (which an experienced coder could probably do in a split second), your solution doesn't do much apart from replacing a value of 0,5 to 0,05...

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: adding half value?

    Hi,

    Do you define the cRngPointVal variable data type as integer type (such integer or long) ?

    If yes, then you should change it to decimal hold capable data type (like single or double, or even variant)

    Please Login or Register  to view this content.
    Regards
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  5. #5
    Registered User
    Join Date
    12-17-2012
    Location
    Poland
    MS-Off Ver
    2013
    Posts
    57

    Re: adding half value?

    See, I knew it was a silly thing it's just a matter of lack of knowledge and experience.

    Of course that was the issue. Changed Integer to Single and it works perfectly now.

    Thank you!

  6. #6
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: adding half value?

    You are welcome, glad I can help.

    Regards

+ 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. Overtime calculation for adding a half day if after midnight
    By Dan LCI in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-16-2014, 08:03 AM
  2. Replies: 4
    Last Post: 02-11-2011, 08:02 AM
  3. [SOLVED] Adding half an hour to a time value
    By DaZombie in forum Excel General
    Replies: 7
    Last Post: 10-25-2010, 11:41 AM
  4. adding cell reference as half of a range.
    By idunno in forum Excel General
    Replies: 1
    Last Post: 03-24-2010, 06:43 AM
  5. Replies: 2
    Last Post: 08-15-2006, 03:20 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