+ Reply to Thread
Results 1 to 6 of 6

Return zero if UDF-function return error

  1. #1
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2010
    Posts
    230

    Return zero if UDF-function return error

    I made a user defined function like the one below for a special purpose. The function works fine, but I want it to return 0 (zero) if the functions return an error like #value. Any suggestion on what I have to add to this function?

    Please Login or Register  to view this content.
    Last edited by mkvassh; 10-14-2010 at 08:56 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Return zero if UDF-function return error

    Split is an existing Excel Function & using it as your UDF name will cause problems
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2010
    Posts
    230

    Re: Return zero if UDF-function return error

    OK. The name I use is Split1 in the function (have corrected it above). It is just an example. Do you know how this can return zero if I get an error?

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Return zero if UDF-function return error

    Try:
    Please Login or Register  to view this content.
    Note: I removed the volatile statement as there doesn't appear to be any need for it.
    Remember what the dormouse said
    Feed your head

  5. #5
    Registered User
    Join Date
    08-01-2010
    Location
    American in Rovereto, Italy
    MS-Off Ver
    Excel 2010 home & Excel 2010 work
    Posts
    46

    Re: Return zero if UDF-function return error

    I gather that you expect to split a string numbers with your UDF.
    To return a zero when there is an error, I set the return value to zero at the start of the UDF, and then enabled on error goto errorhandler. That way when when an error happens it will skip to end and the value is already set.

    Please Login or Register  to view this content.
    Last edited by gmahlert; 10-14-2010 at 08:27 AM. Reason: to fix a spelling mistake
    Gordon in Rovereto, Italy

  6. #6
    Forum Contributor
    Join Date
    11-02-2007
    Location
    Bryne, Norway
    MS-Off Ver
    Microsoft Office Excel 2010
    Posts
    230

    Re: Return zero if UDF-function return error

    Thank you both. This will work. Appreciate your quick answer :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1