View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Newbie problem :(

For newbies, no "stupid" questions - we all had to learn!
You need to make the Function Public (and put it in a code module you
insert, not in ThisWorkbook or the worksheet's code module):

Public Function Foo()
Foo = 42
End Function

Functions can only be used within their own code module unless you make them
Public.
--
- K Dales


"Liosan" wrote:


Hello people,

im new to using VBA, and im having a rather stupid problem. I am trying
to write a function that i could use inside the worksheet, e.g. A1
=Foo(). I tried
Code:
--------------------
Function Foo()
Foo = 42
End Function
--------------------
and several variations on that theme, but the only effect i'm getting
is #NAME errors. Does a function have to be registered in some way
before being used on a sheet? or do i have to use CALL in some way?

Thanks for any help,

Liosan


--
Liosan
------------------------------------------------------------------------
Liosan's Profile: http://www.excelforum.com/member.php...o&userid=26296
View this thread: http://www.excelforum.com/showthread...hreadid=395765