4

For some reason custom functions don't seem to be running in Excel. I created the simple function below but it always returns zero as a value whether it is used as a worksheet function or called from a procedure. Anyone know what I am doing wrong or if there is a setting somewhere I am missing?

  Public Function Testthisout(number As Double) As Double
    result = number * number
  End Function

  Public Sub TESTFUNCTION()
    Dim number As Double
    Dim result As Double

    Application.Volatile (True)

    number = 4
    result = Testthisout(number)
    MsgBox result
  End Sub

1 Answer 1

3

Change you function to:

Public Function Testthisout(number As Double) As Double
  result = number * number
  Testthisout = result
End Function
Sign up to request clarification or add additional context in comments.

3 Comments

nope, still get 0 returned. Dunno if I have to reinstall excel maybe
Try Testthisout = number * number. Your problem is that you don't assign result to the function's returning value.
Many thanks- obvious in hindsight, but highly frustating when you miss it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.