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.
AH! I see! Thanks!
No difference in robustness involved...
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:
If you prefer 'match' you can use it's variable vartype:Sub tst() msgbox = Application.CountIf([A1:A10], "ccc") & " times found" End Sub
Sub tst() msgbox if(VarType(Application.Match("ccc", [A1:A10], 0))=10,"not ","") & "found" End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks