ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problem trapping an error (https://www.excelbanter.com/excel-programming/299050-problem-trapping-error.html)

keith

Problem trapping an error
 
Hello,
I am writing a function to show the error number and name
for errors found in an Excel worksheet cell. I am passing
the cell contents to the function "Show_Error_Number(Val1
as variant) and then working with the error in the
function. The first step is to capture and debug.print
the error number. However, I've been unable to actually
capture the number using Err.Number or Error.Type.
How can I do this.

My code is shown below.

Public Function Show_Error_Number(val1 As Variant)

If IsError(val1) Then

Debug.print val1 ' for #NUM! error this prints "Error
2036" but I am unable to work with it as a string

'Show_Error_Number = Err.Number ' doesn't work
Show_Error_Number = Error.Type ' doesn't work

Else

Show_Error_Number = 99999999

End If


Thanks

Keith


End Function



All times are GMT +1. The time now is 02:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com