PC Review


Reply
Thread Tools Rate Thread

How can I make my function result in an error

 
 
Michelle
Guest
Posts: n/a
 
      14th Aug 2009
I'm writing a UD Function, and if the user enters a range wrong, I want the
function to result in #VALUE or #N/A.

How do I code that into my function?

Thanks

M

 
Reply With Quote
 
 
 
 
Bob Umlas
Guest
Posts: n/a
 
      14th Aug 2009
Function MyFunc()
MyFunc= CVErr(xlErrValue)
'or MyFunc=CVErr(xlErrNA)
End Function
Bob Umlas
Excel MVP

"Michelle" <(E-Mail Removed)> wrote in message
news:8676A4E1-DD21-4648-B47E-(E-Mail Removed)...
> I'm writing a UD Function, and if the user enters a range wrong, I want
> the function to result in #VALUE or #N/A.
>
> How do I code that into my function?
>
> Thanks
>
> M



 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      14th Aug 2009
From VBA Help:

Cell Error Values
You can insert a cell error value into a cell or test the value of a cell
for an error value by using the CVErr function. The cell error values can be
one of the following XlCVError constants.

Constant Error number Cell error value
xlErrDiv0 2007 #DIV/0!
xlErrNA 2042 #N/A
xlErrName 2029 #NAME?
xlErrNull 2000 #NULL!
xlErrNum 2036 #NUM!
xlErrRef 2023 #REF!
xlErrValue 2015 #VALUE!


Example
This example inserts the seven cell error values into cells A1:A7 on Sheet1.

myArray = Array(xlErrDiv0, xlErrNA, xlErrName, xlErrNull, _
xlErrNum, xlErrRef, xlErrValue)
For i = 1 To 7
Worksheets("Sheet1").Cells(i, 1).Value = CVErr(myArray(i - 1))
Next i

This example displays a message if the active cell on Sheet1 contains a cell
error value. You can use this example as a framework for a cell-error-value
error handler.

Worksheets("Sheet1").Activate
If IsError(ActiveCell.Value) Then
errval = ActiveCell.Value
Select Case errval
Case CVErr(xlErrDiv0)
MsgBox "#DIV/0! error"
Case CVErr(xlErrNA)
MsgBox "#N/A error"
Case CVErr(xlErrName)
MsgBox "#NAME? error"
Case CVErr(xlErrNull)
MsgBox "#NULL! error"
Case CVErr(xlErrNum)
MsgBox "#NUM! error"
Case CVErr(xlErrRef)
MsgBox "#REF! error"
Case CVErr(xlErrValue)
MsgBox "#VALUE! error"
Case Else
MsgBox "This should never happen!!"
End Select
End If


--
Gary''s Student - gsnu200860


"Michelle" wrote:

> I'm writing a UD Function, and if the user enters a range wrong, I want the
> function to result in #VALUE or #N/A.
>
> How do I code that into my function?
>
> Thanks
>
> M
>
>

 
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
how to make an IF function that has the same result as COUNTIF? Alex Khan Microsoft Excel Worksheet Functions 3 24th Jul 2008 11:15 PM
Re: how to make an IF function that has the same result as COUNTIF? Peo Sjoblom Microsoft Excel Worksheet Functions 0 24th Jul 2008 09:41 PM
How do I make a cell blank if Error OR 0 Result Gregory Day Microsoft Excel Worksheet Functions 2 26th Mar 2008 05:14 PM
Len and left function- result #Error. mohsin via AccessMonster.com Microsoft Access Queries 3 25th Oct 2007 04:12 PM
How to make the Result of a TODAY Function static? kscramm Microsoft Excel Worksheet Functions 11 23rd Mar 2006 08:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:48 PM.