+ Reply to Thread
Results 1 to 6 of 6

UDF Division Problem what operator?

  1. #1
    Valued Forum Contributor
    Join Date
    02-04-2009
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    665

    UDF Division Problem what operator?

    I have broken my big User Defined Function down into parts to see where the mishap is...

    Here is what I have found:
    Please Login or Register  to view this content.
    The facter is.58 and the Listcost is 4888, so the result should be: 8,427.58 - what it is giving is: 4888.

    Can anyone see what is amiss?

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: UDF Division Problem what operator?

    change your data type to doubple

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    02-04-2009
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    665

    Re: UDF Division Problem what operator?

    Why did that work? Because of the Division?

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,858

    Re: UDF Division Problem what operator?

    Integer data types can only store integers. 0.58 is not an integer, so when VBA stores 0.58 in an integer variable, it rounds it to the nearest integer (1 in this case). 4888/1=4888

    Double is the data type that is meant to be used when storing and doing math on non-integer numbers.

  5. #5
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: UDF Division Problem what operator?

    What happened is that when .58 was passed to your function Lcost it rounded .58 to the nearest whole number (integer) so that 4888 / 1 = 4888. If facter was .48, you would have gotten a divide by zero error, because the nearest whole number to .48 is zero.

  6. #6
    Valued Forum Contributor
    Join Date
    02-04-2009
    Location
    Texas
    MS-Off Ver
    Excel 2016
    Posts
    665

    Re: UDF Division Problem what operator?

    Gotcha - It is now working for 98% of the lines in my sheet, some return Number errors and some return value errors - everything else is right. I am going through trying to evaluate the difference. Thanks for all the help guys. I love this forum.

+ 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