PC Review


Reply
Thread Tools Rate Thread

Calling a public function from a worksheet

 
 
JWirt
Guest
Posts: n/a
 
      19th Sep 2008
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



 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      19th Sep 2008
You have Pulic Function!

try...

Public Function

--

Regards,
Nigel
(E-Mail Removed)



"JWirt" <(E-Mail Removed)> wrote in message
news:5FFE5EC1-746D-470E-83C4-(E-Mail Removed)...
> 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
>
>
>


 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      19th Sep 2008
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" <(E-Mail Removed)> wrote in message
news:5FFE5EC1-746D-470E-83C4-(E-Mail Removed)...
> 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
>
>
>



 
Reply With Quote
 
aushknotes
Guest
Posts: n/a
 
      19th Sep 2008
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
>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      19th Sep 2008
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
 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      19th Sep 2008
"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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling Public Function nomadk Microsoft Access Form Coding 2 2nd Sep 2008 02:32 PM
calling a public function correctly lambertsm via AccessMonster.com Microsoft Access Form Coding 5 12th Jan 2008 03:38 PM
Calling a Public Function David Microsoft Excel Programming 1 28th Sep 2007 03:00 PM
Calling a Public Function tobesurveyor via AccessMonster.com Microsoft Access VBA Modules 3 28th Apr 2006 09:13 AM
Calling public function from a control George Papadopoulos Microsoft Access 4 5th Apr 2004 02:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:23 PM.