Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Calling Match function from code

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Calling Match function from code

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").v alue, _
.range("b1:b99"), 0)
end with
if err.number < 0 then
'no match
err.clear
else
'match found
end if
on error goto 0




Backslider wrote:

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


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Calling Match function from code

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

Dave Peterson wrote:

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").v alue, _
.range("b1:b99"), 0)
end with
if err.number < 0 then
'no match
err.clear
else
'match found
end if
on error goto 0

Backslider wrote:

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


--

Dave Peterson


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling VBA code from html or javascript Brent E Excel Discussion (Misc queries) 0 October 16th 08 11:27 PM
Calling a bit of code from a sheet errors gearoi Excel Discussion (Misc queries) 2 September 6th 05 08:21 PM
Match Function(Code modification) Todd Huttenstine\(Remote\) Excel Programming 3 November 28th 03 06:14 AM
Calling an XLA macro from code Chrissy[_4_] Excel Programming 2 October 11th 03 04:38 PM
Calling HTML Source code from within VBA for Excel Peter Dickson Excel Programming 0 July 9th 03 08:38 PM


All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"