Results 1 to 2 of 2

Custom VBA function gives different solution than regular Excel functions (same formulae)

Threaded View

jimmypants Custom VBA function gives... 01-05-2014, 03:12 AM
jimmypants Re: Custom VBA function gives... 01-05-2014, 05:22 AM
  1. #1
    Registered User
    Join Date
    12-23-2011
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Custom VBA function gives different solution than regular Excel functions (same formulae)

    Using MS Excel 2003 on XP...
    Anyone have any ideas regarding what might cause the following discrepancy and how it might be corrected?

    I am attempting to stop using the Solver Tool for some optimizations that do not require Newtonian convergence...

    I created a custom optimization function in VBA. It solves to what first appears to be an acceptable value, but when I checked it against what I get via the exact same formula set in Excel (iteration via Solver Tool instead of VBA), the VBA solution value is significantly different (+/-5.0E-3 relative accuracy) even though all formulae and constants are exactly the same. This discrepancy is unacceptable. I do not even know which venue is more accurate (Excel or VBA).

    I am seeking a solution that has relative accuracy +/-1.0E-5 or better. What I mean by "relative accuracy" is xUsed/xAccurate-1 = {relative accuracy}.

    It is important to note that I am using exponents and logarithm functions, though not "aggressively" (I think).

    I created a custom test function with logarithms and compared its result to that of a plain Excel formula (no VBA)... I saw that "as single" and "as double" made a difference there, but even when I set everything to "as double" in my original VBA formula, the discrepancy did not go away and actually did not change at all. Double gave the exact same answer as single in the original VBA formula. Sample code from test function, feel free to play around with it:
    Function logTest1(meow1 As Single, meow2 As Single) As Double
        logTest1 = Log(meow1) / Log(meow2)
    End Function
    It is interesting to note that another VBA test function using Excel formula behaved just like the VBA native formula:
    Function logTest2(meow1 As Single, meow2 As Single) As Double
        logTest2 = Application.WorksheetFunction.Log(meow1, meow2)
    End Function
    Anyone have any ideas regarding what might cause such a discrepancy and how it might be corrected?
    Last edited by jimmypants; 01-05-2014 at 05:54 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 03-01-2012, 09:38 AM
  2. Create custom function to exceed 7 nested If functions in Excel 2003/XP/2000/97
    By seanyeap in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2008, 08:54 AM
  3. [SOLVED] Need to reference existing functions in a custom function: possibl
    By dofnup in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM
  4. [SOLVED] Need to reference existing functions in a custom function: possibl
    By dofnup in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  5. [SOLVED] Need to reference existing functions in a custom function: possibl
    By dofnup in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-06-2005, 07:05 AM

Tags for this Thread

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