ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I get a UDF to return #N/A, as if from =NA() (https://www.excelbanter.com/excel-programming/429592-re-how-do-i-get-udf-return-n-if-%3Dna.html)

Peter T

How do I get a UDF to return #N/A, as if from =NA()
 
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" wrote in message
...
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





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com