Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Using IsError with Match

I have a list box from which a user may select a client. My code then looks
through a list of employees to find the ones belonging to that client. For
various reasons, it is possible to select a client that might not be
represented in the list of employees (it's necessary, I assure you). In case
the user selects a client that isn't in the employee list, I wanted to catch
this and avoid an error message. The code that is supposed to do this is
below.

If IsError(Application.WorksheetFunction.Match(Client Num, ClientEEs, 0)) =
True Then
' Do stuff
End If

However, I still get the "Unable to get the Match property of the
WorksheetFunction class" error message. I don't really want to use On Error
Resume Next because, if the user selects a client not in the list of
employees, I've got a whole section of code I want to skip over.

How can I make this work so that it sees the error, sets a couple of
variables equal to 0, then continues at a different point in the code?

Thanks for any help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Using IsError with Match

That should work. It can be shortened to

If IsError(Application.Match(ClientNum, ClientEEs, 0)) Then
' Do stuff
End If

but that is essentially the same.

You could use Onerror like so

On Error Resume Next
idx =Application.Match(ClientNum, ClientEEs, 0))
On Error Goto 0
If idx 0 Then
'Do stuff
End If


--

HTH

Bob

"Luke" wrote in message
...
I have a list box from which a user may select a client. My code then
looks
through a list of employees to find the ones belonging to that client.
For
various reasons, it is possible to select a client that might not be
represented in the list of employees (it's necessary, I assure you). In
case
the user selects a client that isn't in the employee list, I wanted to
catch
this and avoid an error message. The code that is supposed to do this is
below.

If IsError(Application.WorksheetFunction.Match(Client Num, ClientEEs, 0)) =
True Then
' Do stuff
End If

However, I still get the "Unable to get the Match property of the
WorksheetFunction class" error message. I don't really want to use On
Error
Resume Next because, if the user selects a client not in the list of
employees, I've got a whole section of code I want to skip over.

How can I make this work so that it sees the error, sets a couple of
variables equal to 0, then continues at a different point in the code?

Thanks for any help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using IsError with Match

Drop the .worksheetfunction portion:

if IsError(Application.Match(....



Luke wrote:

I have a list box from which a user may select a client. My code then looks
through a list of employees to find the ones belonging to that client. For
various reasons, it is possible to select a client that might not be
represented in the list of employees (it's necessary, I assure you). In case
the user selects a client that isn't in the employee list, I wanted to catch
this and avoid an error message. The code that is supposed to do this is
below.

If IsError(Application.WorksheetFunction.Match(Client Num, ClientEEs, 0)) =
True Then
' Do stuff
End If

However, I still get the "Unable to get the Match property of the
WorksheetFunction class" error message. I don't really want to use On Error
Resume Next because, if the user selects a client not in the list of
employees, I've got a whole section of code I want to skip over.

How can I make this work so that it sees the error, sets a couple of
variables equal to 0, then continues at a different point in the code?

Thanks for any help.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default Using IsError with Match

Worked like a charm. Thank you very much.

If you don't mind, though, can you tell me why that made a difference?

Thanks.

"Dave Peterson" wrote:

Drop the .worksheetfunction portion:

if IsError(Application.Match(....



Luke wrote:

I have a list box from which a user may select a client. My code then looks
through a list of employees to find the ones belonging to that client. For
various reasons, it is possible to select a client that might not be
represented in the list of employees (it's necessary, I assure you). In case
the user selects a client that isn't in the employee list, I wanted to catch
this and avoid an error message. The code that is supposed to do this is
below.

If IsError(Application.WorksheetFunction.Match(Client Num, ClientEEs, 0)) =
True Then
' Do stuff
End If

However, I still get the "Unable to get the Match property of the
WorksheetFunction class" error message. I don't really want to use On Error
Resume Next because, if the user selects a client not in the list of
employees, I've got a whole section of code I want to skip over.

How can I make this work so that it sees the error, sets a couple of
variables equal to 0, then continues at a different point in the code?

Thanks for any help.


--

Dave Peterson
.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Using IsError with Match

Just the way Microsoft implemented it (same with =vlookup(), too).

dim res as variant
on error resume next
res = application.worksheetfunction.match(...)
if err.number < 0 then
'an error
err.clear
res = "error"
end if
on error goto 0

Would be an alternative way of using application.worksheetfunction or just
worksheetfunction.



Luke wrote:

Worked like a charm. Thank you very much.

If you don't mind, though, can you tell me why that made a difference?

Thanks.

"Dave Peterson" wrote:

Drop the .worksheetfunction portion:

if IsError(Application.Match(....



Luke wrote:

I have a list box from which a user may select a client. My code then looks
through a list of employees to find the ones belonging to that client. For
various reasons, it is possible to select a client that might not be
represented in the list of employees (it's necessary, I assure you). In case
the user selects a client that isn't in the employee list, I wanted to catch
this and avoid an error message. The code that is supposed to do this is
below.

If IsError(Application.WorksheetFunction.Match(Client Num, ClientEEs, 0)) =
True Then
' Do stuff
End If

However, I still get the "Unable to get the Match property of the
WorksheetFunction class" error message. I don't really want to use On Error
Resume Next because, if the user selects a client not in the list of
employees, I've got a whole section of code I want to skip over.

How can I make this work so that it sees the error, sets a couple of
variables equal to 0, then continues at a different point in the code?

Thanks for any help.


--

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
IF ISERROR INDIRECT MATCH Formula Question??? grateful Excel Worksheet Functions 19 September 21st 09 03:01 AM
MATCH() and ISERROR() to extract set differences Jim Fradkin Excel Programming 1 January 9th 09 11:26 PM
IF ISERROR with index match aileen Excel Programming 3 November 4th 08 06:46 PM
IsError and Match function GDCross Excel Programming 7 May 26th 06 07:49 PM
IF(ISERROR(MATCH - need value where match was found Ed[_9_] Excel Programming 2 November 12th 03 09:02 PM


All times are GMT +1. The time now is 01:51 AM.

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"