Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Calling a public function from a worksheet

When I call this public function from a worksheet cell (e.g., =Nspaces(7)),
the result is #NAME?

Pulic Function Nspaces(NumSp As Integer)
Dim Nspaces1 As String
Nspaces1 = ""
While Len(Nspaces) < NumSp
Nspaces1 = Nspaces1 & " "
Wend
Nspaces = Nspaces1
End Function

Why?

I created this function in a separate module in Personal.xls.

Thank you.

John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Calling a public function from a worksheet

UDF's need to be either in the workbook from which they are called or in an
addin. So your function won't work if in your Personal.xls (except of course
if called from personal.xls).

In passing, I'd change the "As Integer" to "As Long".

Regards,
Peter T

"JWirt" wrote in message
...
When I call this public function from a worksheet cell (e.g.,
=Nspaces(7)),
the result is #NAME?

Pulic Function Nspaces(NumSp As Integer)
Dim Nspaces1 As String
Nspaces1 = ""
While Len(Nspaces) < NumSp
Nspaces1 = Nspaces1 & " "
Wend
Nspaces = Nspaces1
End Function

Why?

I created this function in a separate module in Personal.xls.

Thank you.

John





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Calling a public function from a worksheet

Hi,

You have to put your function in a module. BTW you can simplify your
function as follow:

Function Nspaces(NumSp As Integer)
Nspaces = space(Numsp)
End Function

Cheers,






"JWirt" wrote:

When I call this public function from a worksheet cell (e.g., =Nspaces(7)),
the result is #NAME?

Pulic Function Nspaces(NumSp As Integer)
Dim Nspaces1 As String
Nspaces1 = ""
While Len(Nspaces) < NumSp
Nspaces1 = Nspaces1 & " "
Wend
Nspaces = Nspaces1
End Function

Why?

I created this function in a separate module in Personal.xls.

Thank you.

John



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Calling a public function from a worksheet

try:
=personal.xls!nspaces(7)
(and fix the public typo)

or use:
=rept(" ",7)



JWirt wrote:

When I call this public function from a worksheet cell (e.g., =Nspaces(7)),
the result is #NAME?

Pulic Function Nspaces(NumSp As Integer)
Dim Nspaces1 As String
Nspaces1 = ""
While Len(Nspaces) < NumSp
Nspaces1 = Nspaces1 & " "
Wend
Nspaces = Nspaces1
End Function

Why?

I created this function in a separate module in Personal.xls.

Thank you.

John


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Calling a public function from a worksheet

"Peter T" <peter_t@discussions wrote in message
UDF's need to be either in the workbook from which they are called or in
an addin. So your function won't work if in your Personal.xls


-er, unless of course you fully qualify the function in cell formulas along
the lines as suggested by Dave

Regards,
Peter T


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling a Public Function David Excel Programming 1 September 28th 07 03:00 PM
Calling Public Variables between diff Modules J@Y Excel Programming 3 July 4th 07 06:16 PM
Calling? Invoke Public Function Chip Pearson Excel Programming 0 January 18th 07 10:13 PM
calling VBA function within a worksheet matelot Excel Programming 2 March 20th 06 06:45 PM
Calling a Public Subroutine in a Different Workbook Raul Excel Programming 2 August 24th 05 04:27 AM


All times are GMT +1. The time now is 01:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"