PC Review


Reply
Thread Tools Rate Thread

How do I get a UDF to return #N/A, as if from =NA()

 
 
Barb Reinhardt
Guest
Posts: n/a
 
      10th Jun 2009
I have a user defined function and at times I want it to return =NA() in the
cell. How do I do this? I can get it to return a text string, but not a
formula.

Thanks,
Barb Reinhardt
 
Reply With Quote
 
 
 
 
Jacob Skaria
Guest
Posts: n/a
 
      10th Jun 2009
Try

returnvalue = "=#N/A"

If this post helps click Yes
---------------
Jacob Skaria


"Barb Reinhardt" wrote:

> I have a user defined function and at times I want it to return =NA() in the
> cell. How do I do this? I can get it to return a text string, but not a
> formula.
>
> Thanks,
> Barb Reinhardt

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      10th Jun 2009
Oops..

=NA() only works in worksheet .

If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

> Try
>
> returnvalue = "=#N/A"
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Barb Reinhardt" wrote:
>
> > I have a user defined function and at times I want it to return =NA() in the
> > cell. How do I do this? I can get it to return a text string, but not a
> > formula.
> >
> > Thanks,
> > Barb Reinhardt

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      10th Jun 2009
I already tried "=NA()" and I get

=NA()

in the cell. It doesn't behave like the formula =NA().

Any other suggestions?

"Jacob Skaria" wrote:

> Oops..
>
> =NA() only works in worksheet .
>
> If this post helps click Yes
> ---------------
> Jacob Skaria
>
>
> "Jacob Skaria" wrote:
>
> > Try
> >
> > returnvalue = "=#N/A"
> >
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "Barb Reinhardt" wrote:
> >
> > > I have a user defined function and at times I want it to return =NA() in the
> > > cell. How do I do this? I can get it to return a text string, but not a
> > > formula.
> > >
> > > Thanks,
> > > Barb Reinhardt

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      10th Jun 2009
Try

returnvalue = CVErr(xlErrNA)

If this post helps click Yes
---------------
Jacob Skaria


"Barb Reinhardt" wrote:

> I already tried "=NA()" and I get
>
> =NA()
>
> in the cell. It doesn't behave like the formula =NA().
>
> Any other suggestions?
>
> "Jacob Skaria" wrote:
>
> > Oops..
> >
> > =NA() only works in worksheet .
> >
> > If this post helps click Yes
> > ---------------
> > Jacob Skaria
> >
> >
> > "Jacob Skaria" wrote:
> >
> > > Try
> > >
> > > returnvalue = "=#N/A"
> > >
> > > If this post helps click Yes
> > > ---------------
> > > Jacob Skaria
> > >
> > >
> > > "Barb Reinhardt" wrote:
> > >
> > > > I have a user defined function and at times I want it to return =NA() in the
> > > > cell. How do I do this? I can get it to return a text string, but not a
> > > > formula.
> > > >
> > > > Thanks,
> > > > Barb Reinhardt

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      10th Jun 2009
Function foo(v)
' try v = 0 and v = 1
On Error GoTo errH
foo = 1 / v

Err.Raise 12345
Exit Function
errH:
If Err.Number = 11 Then
foo = CVErr(xlErrDiv0)
ElseIf Err.Number = 12345 Then
foo = CVErr(xlErrNA)
Else
foo = CVErr(xlErrValue)
End If
End Function

here are the XlCVError constants

xlErrDiv0
xlErrNA
xlErrName
xlErrNull
xlErrNum
xlErrRef
xlErrValue


Regards,
Peter T

"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:F7624D0C-AA8E-4106-A66E-(E-Mail Removed)...
>I have a user defined function and at times I want it to return =NA() in
>the
> cell. How do I do this? I can get it to return a text string, but not a
> formula.
>
> Thanks,
> Barb Reinhardt



 
Reply With Quote
 
Ron Rosenfeld
Guest
Posts: n/a
 
      10th Jun 2009
On Wed, 10 Jun 2009 04:43:01 -0700, Barb Reinhardt
<(E-Mail Removed)> wrote:

>I have a user defined function and at times I want it to return =NA() in the
>cell. How do I do this? I can get it to return a text string, but not a
>formula.
>
>Thanks,
>Barb Reinhardt


A function can only return a value. If you want to set a formula into the
cell, you'll need to use a different method (e.g. Sub).

However, if having your formula return the #NA error (not the string; the
error) is acceptable, then you could set your result equal to CVErr(xlErrNA).

The only potential caveat is that you'd need to use a variant for your result.

e.g:

======================
Function FooBar() As Variant
FooBar = CVErr(xlErrNA)
End Function
====================
--ron
 
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
Search and replace hard-line-return character, not carriage return =?Utf-8?B?VHlsZXIgVA==?= Microsoft Word Document Management 2 16th Aug 2006 09:11 PM
Serialize a class having property that return object as return type surindersaini@gmail.com Microsoft C# .NET 4 24th Oct 2005 03:23 PM
VBA to apply a Soft Return (or Hard Return) at end of wrapped line Dennis Microsoft Word Document Management 7 14th May 2005 07:01 AM
Userenv 1000. Windows cannot determine the user or computer name. Return value (<return error code>). Ingmar Microsoft Windows 2000 Networking 1 18th Nov 2003 05:08 PM
Userenv 1000. Windows cannot determine the user or computer name. Return value (<return error code>). Ingmar Microsoft Windows 2000 Group Policy 1 18th Nov 2003 05:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:50 PM.