View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Eric White[_2_] Eric White[_2_] is offline
external usenet poster
 
Posts: 45
Default Error Handling to mitigate "Run Time Erorr 13 Type Mismatch"

On Error Resume Next
If Application.HLookup(sh.Name, WorkSheetSelectForm.SheetExcludeArray, 2,
False) = 0 Then
Select Case Err.Number
Case 0
'Action to do if there is no error
Case 13
'Action to do if sh.Name does not exist in array

'Case... i.e., any other errors you need to trap

Case Else
'Any unexpected/unhandled errors
End Select
On Error Goto 0 'Turn auto error control back on


"ExcelMonkey" wrote:

I have a line of code that is failing due to a Run Time Error 13 Type
Mismatch. The code is as following:

If Application.HLookup(sh.Name, WorkSheetSelectForm.SheetExcludeArray, 2,
False) = 0 Then

Now I know why its failing. The term sh.Name does not exisit in the Array
that I am performing the Hlookup on. However, I need to warp error handling
around this so that the code will progress. I have tried wrapping a ISERROR
stmt around it to generate a boolean as a start. But I cannot get this to
work. When I do the following below in the Immediate Window I get a "Run
Time Error 1001Unable to get the Hlookup Property of the Worksheet Function
class"

?ISERROR(Application.worksheetfunction.HLookup(sh. Name,
WorkSheetSelectForm.SheetExcludeArray, 2, False) = 0)

What can I do in order to error handle this?

Thanks