LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Error handling in vba function

You could also use other errors. So your unequal ranges could be

if MyRange1.Cells.Count < MyRange2.Cells.Count then
myFunc = CvErr(xlErrRef)
End Function
End If

and use #Value for some otherv error. Your user instructions could tell the
user what each error means.


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jaap Versteegh" wrote in message
...
Hi
use the CVErr function in the VBA help


Thanks for the response Frank, but how would this help ?

Problem:
A vba (worksheet)function needs 2 ranges as parameters, but they both need
to be of the same size. I would like to notify the user when they aren't
rather than just return "#VALUE" in the cell.

So something like:

function MyFunc (MyRange1 as Range, MyRange2 as Range)
On Error GoTo ErrorHandler
if MyRange1.Cells.Count < MyRange2.Cells.Count then
Err.Raise 1000, "MyFunc", "Ranges not of same size !"
end if
' Do the stuff the function does here !
Exit Function
ErrorHandler:
' Now here I would like to tell the user of this function what the

problem
is ...
MsgBox Err.Description
' This however causes problems when entering the function from the

formula
bar after
' clicking the equal sign - the function is invoked before the second
range has been entered
' completely, so the ranges are not of the same size (yet). The message
box is displayed so
' the user can't complete the entry of the second parameter....

' Re-raise the error so the function will return #VALUE !
Err.Raise 1000
End Function

TIA for any further suggestions...

Regards
Frank








 
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
Error Handling #N/A with AVERAGE Function - Average of values in Row Sam via OfficeKB.com Excel Worksheet Functions 13 July 31st 05 03:59 PM
Error handling V. Roe Excel Programming 2 February 27th 04 08:04 PM
Error Handling Todd Excel Programming 1 February 13th 04 11:29 PM
Error Handling James Agostinho Excel Programming 1 January 30th 04 06:40 AM
Error handling John Pierce Excel Programming 3 October 3rd 03 12:17 PM


All times are GMT +1. The time now is 03:09 AM.

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

About Us

"It's about Microsoft Excel"