+ Reply to Thread
Results 1 to 2 of 2

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

  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:
    Please Login or Register  to view this content.
    It is interesting to note that another VBA test function using Excel formula behaved just like the VBA native formula:
    Please Login or Register  to view this content.
    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.

  2. #2
    Registered User
    Join Date
    12-23-2011
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Custom VBA function gives different solution than regular Excel functions (same formul

    Nevermind, I figured it out...
    I had accidentally mistyped a constant value that is used as an exponent in the custom VBA function.
    Thankfully, the problem was due to my own error!
    Excel + VBA is a wonderful thing!

+ 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. 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