Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Error Handling with Worksheetfunction.Match

Hello,
I am having trouble with error handling. Not sure how much of the code to
include here, as I cant really tell where the issue is. Heres the sub
routine where its breaking down:
===========
MoveData:
On Error GoTo BadProjectName
ToRowNum = Application.WorksheetFunction.Match(ProjNme,
ToRng.Columns(1).Cells, 0)

On Error GoTo IrregularVendor
ToColNum = Application.WorksheetFunction.Match(VendNme, ToRng.Rows(1).Cells,
0) ***err on this line***

On Error GoTo 0
ToRng.Cells(ToRowNum, ToColNum).Value = Rslt

IrregularVendor:
On Error GoTo 0
Return
============
The problem is that, the second time that it encounters an irregular vendor,
I get a run time error (Unable to get the Match property of the
WorksheetFunction class). The fact that it works once leads me to believe
that some sort of setting is being retained, but I can't figure out what it
could be. Ive tried inserting err.clear in various places, with no luck.
If anyone has any suggestions, please let me know.

Excel07, XPPro, VB6.5
--
Mike Lee
McKinney,TX USA
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error Handling with Worksheetfunction.Match

I would just drop the On Error stuff and .worksheetfunction and use:

Dim ToRowNum as Variant 'not long, it could be an error
dim ToColNum as variant 'not long

torownum = application.match(projnme, torng.columns(1), 0)
tocolnum = application.match(vendnme, torng.rows(1),0)

if iserror(torownum) _
or iserror(tocolnum) then
msgbox "at least one mismatch"
else
ToRng.Cells(ToRowNum, ToColNum).Value = Rslt
end if



mikelee101 wrote:

Hello,
I am having trouble with error handling. Not sure how much of the code to
include here, as I cant really tell where the issue is. Heres the sub
routine where its breaking down:
===========
MoveData:
On Error GoTo BadProjectName
ToRowNum = Application.WorksheetFunction.Match(ProjNme,
ToRng.Columns(1).Cells, 0)

On Error GoTo IrregularVendor
ToColNum = Application.WorksheetFunction.Match(VendNme, ToRng.Rows(1).Cells,
0) ***err on this line***

On Error GoTo 0
ToRng.Cells(ToRowNum, ToColNum).Value = Rslt

IrregularVendor:
On Error GoTo 0
Return
============
The problem is that, the second time that it encounters an irregular vendor,
I get a run time error (Unable to get the Match property of the
WorksheetFunction class). The fact that it works once leads me to believe
that some sort of setting is being retained, but I can't figure out what it
could be. Ive tried inserting err.clear in various places, with no luck.
If anyone has any suggestions, please let me know.

Excel07, XPPro, VB6.5
--
Mike Lee
McKinney,TX USA


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error Handling with Worksheetfunction.Match

ps. Clear the error (err.clear) and then try Resume Next.

pps. I like the Variants, using application.match() and checking for errors
better. I think it's easier to understand.

mikelee101 wrote:

Hello,
I am having trouble with error handling. Not sure how much of the code to
include here, as I cant really tell where the issue is. Heres the sub
routine where its breaking down:
===========
MoveData:
On Error GoTo BadProjectName
ToRowNum = Application.WorksheetFunction.Match(ProjNme,
ToRng.Columns(1).Cells, 0)

On Error GoTo IrregularVendor
ToColNum = Application.WorksheetFunction.Match(VendNme, ToRng.Rows(1).Cells,
0) ***err on this line***

On Error GoTo 0
ToRng.Cells(ToRowNum, ToColNum).Value = Rslt

IrregularVendor:
On Error GoTo 0
Return
============
The problem is that, the second time that it encounters an irregular vendor,
I get a run time error (Unable to get the Match property of the
WorksheetFunction class). The fact that it works once leads me to believe
that some sort of setting is being retained, but I can't figure out what it
could be. Ive tried inserting err.clear in various places, with no luck.
If anyone has any suggestions, please let me know.

Excel07, XPPro, VB6.5
--
Mike Lee
McKinney,TX USA


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Error Handling with Worksheetfunction.Match

MATCH, like VLOOKUP and HLOOKUP functions raise an error when used but
there's no match

my preference is to create a UDF to handle these
With Match, returning a zero would indicate no match

so
ToColNum = Application.WorksheetFunction.Match(VendNme, ToRng.Rows(1).Cells,
0)


would become
ToColNum = SafeMatch(VendNme, ToRng.Rows(1).Cells)
If ToColNum=0 then
' handle the no match found condition
end if


in you module add this
FUNCTION SafeMatch(what as string, where as range) as long
on error resume next
SafeMatch = Application.WorksheetFunction.Match(what,where,fal se)
on error goto 0
END FUNCTION




"mikelee101" <mikelee101athotmaildotcom wrote in message
...
Hello,
I am having trouble with error handling. Not sure how much of the code to
include here, as I cant really tell where the issue is. Heres the sub
routine where its breaking down:
===========
MoveData:
On Error GoTo BadProjectName
ToRowNum = Application.WorksheetFunction.Match(ProjNme,
ToRng.Columns(1).Cells, 0)

On Error GoTo IrregularVendor
ToColNum = Application.WorksheetFunction.Match(VendNme,
ToRng.Rows(1).Cells,
0) ***err on this line***

On Error GoTo 0
ToRng.Cells(ToRowNum, ToColNum).Value = Rslt

IrregularVendor:
On Error GoTo 0
Return
============
The problem is that, the second time that it encounters an irregular
vendor,
I get a run time error (Unable to get the Match property of the
WorksheetFunction class). The fact that it works once leads me to believe
that some sort of setting is being retained, but I can't figure out what
it
could be. Ive tried inserting err.clear in various places, with no luck.
If anyone has any suggestions, please let me know.

Excel07, XPPro, VB6.5
--
Mike Lee
McKinney,TX USA


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
worksheetfunction.match Li Jianyong[_2_] Excel Programming 11 March 10th 10 10:07 PM
Match Error Handling CB Excel Programming 2 September 4th 08 01:16 AM
Error handling with a handling routine ben Excel Programming 0 March 15th 05 03:01 PM
Error Handling with a Match Function. Hari Prasadh Excel Programming 5 February 2nd 05 04:11 PM
worksheetfunction.match David Robinson[_3_] Excel Programming 4 November 15th 03 06:35 PM


All times are GMT +1. The time now is 10:12 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"