+ Reply to Thread
Results 1 to 9 of 9

MATCH and capturing the error

  1. #1
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Question MATCH and capturing the error

    In the help file for MATCH it says:
    If MATCH is unsuccessful in finding a match, it returns the #N/A error value.
    So I am trying in vain to capture the error, but can't see where I am going wrong.

    Please Login or Register  to view this content.
    All I get in the watch window for 'response' is 'Empty'
    Why aren't I getting the #N/A error?
    Last edited by Phil_V; 08-06-2009 at 09:11 AM.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: MATCH and capturing the error

    In VBA (as was pointed out to me by romperstomper some time back) it's generally easier to use the Application level Match (not the Worksheet Function), I tend to specify the output as a Variant and test IsNumeric status

    Please Login or Register  to view this content.
    Last edited by DonkeyOte; 08-06-2009 at 08:28 AM. Reason: missing Then (!)

  3. #3
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: MATCH and capturing the error

    I think you're overwriting the error with your resume next/goto 0 lines - if you remove them does it work then?

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: MATCH and capturing the error

    With handlers it will be empty, without the handler the code will simply debug.

    Same is true of say:

    Please Login or Register  to view this content.
    res is empty

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: MATCH and capturing the error

    It is changing from WF to Application that makes it work, even w/o error handling (nothing else in Phil's code needs changing). So what's all that about?

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: MATCH and capturing the error

    I don't know the mechanics behind it but the Application level test returns the actual error value (in this case Error 2042), my point is that using this approach you don't need to insert any handlers at all given the variable has been left as Variant (it can hold the Error type), simply validate the variable.
    Last edited by DonkeyOte; 08-06-2009 at 08:41 AM.

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: MATCH and capturing the error

    OK, thanks DonkeyOte.

  8. #8
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: MATCH and capturing the error

    Cheers both, Application.MATCH it is then

    I had tried WorksheetFunction.MATCH both with an without the error handling, and as DonkeyOte says, with it it didn't work, without it it just dropped to debug

  9. #9
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264

    Re: MATCH and capturing the error

    To use the Worksheetfunction version you'd just need to test to see if the variant was empty before you turned error reporting back on (or store the result in a variable which you could test after the On Error Goto 0 statement).
    Richard Schollar
    Microsoft MVP - Excel

+ 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