Hi
I am trying to perform some math in VBA which is failing. I am creating a user-defined function for someone that takes a number of cell references as input, performs some math, and then outputs the final figure. I want them to be able to call this function from a cell so that the output value is placed in the cell.
This all works fine until near the end of the code where I am trying to get the cube root of a number that can be negative. It is possible to get the cube root of a negative number, and if you do this in a cell
i.e. -1 ^ (1/3)
you get (1.00), which is the real component of the complex number.
However, if I try it in VBA and attempt this code:
Code:
T = CDbl(Application.WorksheetFunction(IMREAL(T ^ (1 / 3))))
I get the error:
"Sub or Function not defined"
for the IMREAL function, so I don't even know if this will work.
Does anyone know if there is a problem using these functions (part of the Analysis Toolpak) in VBA? Also, does anyone know if this will work?
Thanks