Calling Match function from code

B

Backslider

I'm programming Excel from C# (using a VSTO project in Visual Studio .NET).
How do I use the Match function from within code? I've seen macro examples
on the newsgroup that do Application.Match(). But the Application object,
as I see it in C# doesn't have a Match function on it. How can I get to it?

thanks,
Backslider
 
D

Dave Peterson

Maybe you'll find it under:

application.worksheetfunction.match
or even
worksheetfunction.match

But try your code with application.match. It works in Excel's VBA and is easier
to look for a match:

dim res as variant
with activesheet
res = application.match(.range("a1").value, .range("b1:b99"), 0)
end with
if iserror(res) then
'no match
else
'match found
end if

vs.

dim res as long
with activesheet
on error resume next
res = application.worksheetfunction.match(.range("a1").value, _
.range("b1:b99"), 0)
end with
if err.number <> 0 then
'no match
err.clear
else
'match found
end if
 
D

Dave Peterson

I should have added that I know nothing of C#. All these examples work ok in
VBA, though.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top