• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Problem with exponentiation in VBA...

ErikG

New Member
This is one of those situations where I'm missing something really simple/fundamental and I will/should feel embarrassed when I get some help, but here goes...

I started having some trouble using the exponentiation operator "*" in VBA. The errors usually say that an end of statement is expected. So I created a simple UDF to illustrate my problem. The UDF just raises a given number to a given power or raises a given number to the second power. It looks something like this:

Code:
Public Function EXPO(a As Double) As Double
    Dim b As Double
    b = 2#
    EXPO = a^b
End Function

OR

Public Function EXPO(a As Double, b As Double) As Double
    EXPO = a^b
End Function
701317013270134


The errors I am getting back are Compile errors (either Expected: end of statement or Expected: )). I'm can't find examples of the exponentiation operator that are any more complex than "x = a^b". What am I missing? Many thanks in advance for your help!
 
Apologies. I somehow got this into Dashboards when I should have put it into Excel Macros!
 
You just need spaces:

Code:
Public Function EXPO(a As Double) As Double
    Dim b As Double
    b = 2#
    EXPO = a ^ b
End Function
 
Back
Top