Function runs more than once

H

Huyeote

Dear all,

The following function is a sample in Excel's help. When I use it in a
worksheet giving a cell reference as the argument (the cell contains a
formula which refers to other cells), the function runs twice. I mean
when the line End Function was executed, it just went back to the first
line (_If_NumberArg_<_0_Then_) and run all lines
through again. I also have a few DIY functions that run even four times
when used in worksheet.



Code:
--------------------
Function CalculateSquareRoot(NumberArg As Double) As Double
If NumberArg < 0 Then ' Evaluate argument.
Exit Function ' Exit to calling procedure.
Else
CalculateSquareRoot = Sqr(NumberArg) ' Return square root.
End If
End Function
--------------------


Can anyone tell me why is this phenomenon and how to stop this
happening?

Many thanks,

Huyeote
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top