"Match" function returns wrong value
I would think with text, you'd be looking for an exact match.
I'd use something like:
Sub testmatch()
dim res as variant
res = application.match("Invision", _
Workbooks("Book1.xls").Sheets("Sheet1").Range("A:A "), 0)
if iserror(res) then
msgbox "Not found"
else
msgbox res
end if
End Sub
Notice the extra 0 in the =match() function.
ps. You don't need to activate the workbook for this to work. And it's better
to include the extension (assuming the file has been saved).
DarrellK wrote:
Hi,
I am trying to simply return the position of a value in an array using the
"Match" function and I seem to be getting an incorrect result.
I am using the following code:
Sub testmatch()
Workbooks("Book1").Activate
MsgBox (Application.WorksheetFunction.Match("Invision",
Workbooks("Book1").Sheets("Sheet1").Range("A:A")))
End Sub
"Invision" is in row 9 of column A. However, the MsgBox displays 284. There
are entries in rows 2 through 363 if that is of any help.
I would be very grateful for any assitance you could provide. I am using
Visual Basic 6.3 and MS Excel 2003 SP2.
Thanks.
Darrell
--
Dave Peterson
|