+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: Match Function Type Mismatch

  1. #16
    Registered User
    Join Date
    06-10-2011
    Location
    Huntsville, Alabama
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Match Function Type Mismatch

    Quote Originally Posted by snb View Post
    Sub ImportData()
      MsgBox IIf(IsError(Application.Match("FOO", Range("A1:A10"), 0)), "Not found", Application.Match("FOO", Range("A1:A10"), 0))
    End Sub
    I was actually just trying to figure out how to check if no match at all was found, Colin, you mentioned that you wouldn't use the above way due to its multiple calls to Application.Match, is there a more robust solution to this?

  2. #17
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: Match Function Type Mismatch

    Quote Originally Posted by officialhopsof View Post
    I was actually just trying to figure out how to check if no match at all was found, Colin, you mentioned that you wouldn't use the above way due to its multiple calls to Application.Match, is there a more robust solution to this?
    Sure, you can do it using the same methodology as snb suggested but using an If...Else...End If block rather than IIf().
    They're both robust, but the former only calls Application.Match() once so that's how I'd do it. But if you want to use IIf() then I'm certainly not going to stop you!

    Sub ImportData()
        
        Dim vResult As Variant
        
        vResult = Application.Match("FOO", Range("A1:A10"), 0)
        
        If IsError(vResult) Then
            MsgBox "match not found"
        Else
            MsgBox "match found: " & CStr(vResult)
        End If
        
        
    End Sub
    Last edited by Colin Legg; 06-13-2011 at 04:59 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

  3. #18
    Registered User
    Join Date
    06-10-2011
    Location
    Huntsville, Alabama
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Match Function Type Mismatch

    AH! I see! Thanks!

  4. #19
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Match Function Type Mismatch

    No difference in robustness involved...



  5. #20
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Match Function Type Mismatch

    Depending on what you want to achieve ( a test or a result):

    Maybe countif is more appropriate, because the result will always be the same vartype:

    Sub tst()
      msgbox = Application.CountIf([A1:A10], "ccc") & " times found"
    End Sub
    If you prefer 'match' you can use it's variable vartype:

    Sub tst()
      msgbox if(VarType(Application.Match("ccc", [A1:A10], 0))=10,"not ","") & "found"
    End Sub



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0