Reputation: 1816
In the same Workbook, I have defined the function:
Public Function toto(val As Integer) As Integer
toto = val * 2
End Function
Here is the editor view:
And in the Worksheet, in a cell, I use the formula:
But the result is (translation: #NAME?):
Also, in the VBA exec Window itself, opened from Excel, I get the following error when trying to execute:
toto(2)
Translation : Compilation error: Sub or Function not defined
What do I miss?
Upvotes: 0
Views: 1009
Reputation: 606
Expanding on what @Jo.lass and @vincent-g said, you need to have your code in a module, not in worksheet or workbook code. See here:
Upvotes: 3
Reputation: 803
Instead of writing the function in a worksheet in VBE, try writing it in a new module. Works for me at least.
Upvotes: 2