+ Reply to Thread
Results 1 to 3 of 3

Using Excel worksheet functions in VBA for complex numbers

  1. #1
    Registered User
    Join Date
    01-07-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Using Excel worksheet functions in VBA for complex numbers

    Hi - I wrote this simple function:

    Please Login or Register  to view this content.
    But it does not seem to work. Specifically, when I call it from Excel, it just says "=VALUE?"

    It seems to be related to my use of the complex functions. Maybe the complex functions use a unit that can only be handled in the worksheet and not VBA? I believe the brackets are the correct way of calling worksheet functions, but maybe that's causing a problem?

    Thanks!!!

    edit: more information, if useful:

    I'm using Excel 2010.
    I tried enabling both the "analysis toolpak" and the "analysis toolpak - vba" but neither helped. I added a reference to "ATPVBAEN.XLAM" to my VBA project. No dice. Removing the brackets gives me errors, so I think maybe the reference is not working? I know nothing about using references...
    I ran across this page: http://www.excelbanter.com/showthread.php?t=304765 that talks about a potential solution to the problem, but honestly it's way over my head.
    Without the brackets, I got errors. They do seem to work though for at least the Pi() function.
    Last edited by nleahcim; 09-11-2012 at 09:53 PM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,598

    Re: Using Excel worksheet functions in VBA for complex numbers

    a) Fc=worksheetfunction.Complex(...
    b) #? = WorksheetFunction.Pi
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    01-07-2010
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Using Excel worksheet functions in VBA for complex numbers

    Quote Originally Posted by protonLeah View Post
    a) Fc=worksheetfunction.Complex(...
    b) #? = WorksheetFunction.Pi
    Hi! Adding "worksheetfunction." in front of all the complex functions worked great! Any idea why brackets work for pi() but not for the imaginary functions? I should mention I removed the reference to the analysis toolpak and disabled both analysis tookpaks, and everything still works great.

    I don't understand your second suggestion though?

    Anyways - thanks so much for the help!!

    Fixed code is below for anybody in the future that happens upon this thread:

    Please Login or Register  to view this content.

+ 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