I am trying to compute the cube root of a negative number in VBA for Excel. Taking the cube root of a negative number in an Excel worksheet works fine:
=(-2)^(1/3)
-1.25992
However the same concept coded into VBA:
(-2)^(1/3)
gives a #VALUE!error when returning the value to the worksheet. I suspect VBA is parsing the 1/3 to its decimal representation 0.3333... and therefore causing a mathematical error since negative numbers can’t be raised to non-integer powers in the real domain. Is there a workaround?
Try using the
POWER()function: