+ Reply to Thread
Results 1 to 7 of 7

Error Handling when value not found using match

  1. #1
    Registered User
    Join Date
    06-24-2015
    Location
    Oklahoma City
    MS-Off Ver
    2016
    Posts
    28

    Error Handling when value not found using match

    Hi, I have a function that uses match to see if a value is in an array. If it is in the array it returns the position so that I can access corresponding data in other arrays. It works when there is a match but I am having trouble when the value doesnt exist. Below is my function.
    Please Login or Register  to view this content.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Error Handling when value not found using match

    Declare pos as Variant rather than double and then use IsError to check if a match was found.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Error Handling when value not found using match

    Try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Right pos should be declared as Variant
    Last edited by jindon; 05-15-2017 at 11:36 AM.

  4. #4
    Registered User
    Join Date
    06-24-2015
    Location
    Oklahoma City
    MS-Off Ver
    2016
    Posts
    28

    Re: Error Handling when value not found using match

    jindon, that worked. Thank you!

    Just curious. Before I was getting a type mismatch...Is this due to me first declaring pos as a double, and then the match function trying to pass a non double value to pos?

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Error Handling when value not found using match

    That's correct.

    Unlike WorksheetFunction Match method, Application Match method returns Error value when it does not find match, so the variable should be able to receive error value hence Variant type.

  6. #6
    Registered User
    Join Date
    06-24-2015
    Location
    Oklahoma City
    MS-Off Ver
    2016
    Posts
    28

    Re: Error Handling when value not found using match

    That makes a lot of sense now.

    Thank you for your help and the explanation!

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Error Handling when value not found using match

    You are welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Error handling inside error handling
    By grantastley in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-06-2015, 03:43 AM
  2. Error handling in Filter if no record found to be transfer
    By emina002 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-07-2014, 09:51 AM
  3. [SOLVED] Error if no match found
    By SMILE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-16-2013, 05:31 AM
  4. Replies: 3
    Last Post: 04-25-2007, 08:27 AM
  5. Replies: 0
    Last Post: 08-25-2005, 03:46 AM
  6. Error handling with a handling routine
    By ben in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-15-2005, 11:06 AM
  7. [SOLVED] Error Handling with a Match Function.
    By Hari Prasadh in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-02-2005, 01:06 PM

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