Application.Index & Application.Match
res may return an error if there is no match.
should be
res will return an error if there is no match.
or
res may return an error (if there is no match).
Dave Peterson wrote:
And an important note about the difference between application.match and
application.worksheetfunction.match.
If you use
dim res as variant
res = application.match(...)
res may return an error if there is no match.
If you use:
res = application.worksheetfunction.match(...)
and there is no match, then you'll get a runtime error.
You can test for a match using application.match() by using:
if iserror(res) then
'no match...
else
'do the work
end if
You can test for a match using application.worksheetfunction.match(...) by
using:
on error resume next
res = application.worksheetfunction.match(...)
if err.number < 0 then
'no match
err.clear
else
'do the work
end if
on error goto 0
Application.match() looks easier to use (to me, anyway).
The same holds true for application.vlookup() and
application.worksheetfunction.vlookup().
Antonio wrote:
I have seen the following code in a previous question:
Dim N As Variant
Dim arr As Variant
Dim arr2 As Variant
Dim strMessage As String
'Fill the array.
arr = Range("A1:B50").Value
'Return the second column of the array
arr2 = Application.Index(arr, 0, 2)
'Find the position in the array of "77"
N = Application.Match(77, arr2, 0)
I have tried to find help on Application.Index and Application.Match but
have not been successful.
Can someone point me to a help page explaining the syntax of these two
functions.
Thanks,
Antonio
--
Dave Peterson
--
Dave Peterson
|