Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Find the line of code that caused the error?

Hello,

I am trying to write a errandling routine. I have it working fine, but I
would like add one thing. It would be nice to know where in the procedure
the error occurred. Is there a way to get the procedure line number that
caused the error?

Thanks,

Tony
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Find the line of code that caused the error?

Saved from a post by Chip Pearson:

....A far
better solution would be first to download MZTools (www.mztools.com) or a
similar add-in that will automatically add line numbers to code. Then use On
Error Goto <label to display the error. E.g.,

Sub AAA()
Dim WS As Worksheet
On Error GoTo ErrH:
10 Set WS = Worksheets("AAA")
20 Debug.Print "Error line skipped"
30 Exit Sub
ErrH:
40 If MsgBox("Error on line: " & Erl & vbCrLf & _
"Error: " & CStr(Err.Number) & ": " & Err.Description & vbCrLf & _
"Do you want to continue?", vbYesNo) = vbYes Then
50 Resume Next ' optional. do you really want to
60 End If
End Sub

This will tell you exactly where the error occurred and you can change the
code to prompt for a sheet name or workbook name or whatever is necessary to
remedy the problem. You have the option of continuing the code execution if
desired.



Webtechie wrote:

Hello,

I am trying to write a errandling routine. I have it working fine, but I
would like add one thing. It would be nice to know where in the procedure
the error occurred. Is there a way to get the procedure line number that
caused the error?

Thanks,

Tony


--

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
Sumproduct error caused by too many curly brackets? Romileyrunner1 Excel Worksheet Functions 7 September 4th 09 11:12 AM
Error caused by *.xls file WLMPilot Excel Discussion (Misc queries) 0 July 27th 06 03:09 PM
Mysterious Error 1004 caused by AutoFilter? Ken Johnson Excel Programming 5 March 5th 06 08:01 PM
Find Last Line Code: Let's Make This Better coctosten Excel Programming 3 November 12th 05 12:50 AM
Sharing Workbook caused error message Joe Parisi[_2_] Excel Programming 2 October 2nd 03 04:46 PM


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