VBA 

Managing VBA Coding Errors

Error handling refers for error conditions that may arise when your program runs. Errors in general come in three ways:

Compile Time Error:  Such as undeclared variables that prevent your code from compiling and unknown keyword and punctuation omitted.

Logical Error: Occurs when you make a mistake in the logic that drives your script and you do not get the result you expected. You can’t catch these errors, because it depends on your requirement what type of logic you want to put in your code.

Run Time error: That occurs when VBA cannot correctly execute a program statement.

Typical run time errors include attempting to access a non-existent worksheet or workbook, or attempting to divide by zero etc.

On Error: This statement instructs VBA what to do when an run time error is occurred. The On Error statement takes three forms.

 On Error Goto 0:

is the default in VBA.  This indicates that when a run time error occurs VBA should display its default run time error box, allowing you to enter the code in debug mode or to terminate the VBA program.

On Error Resume Next: It instructs to VBA to ignore the error and resume execution on the next line in the sequence. It is very important to remember that On Error Resume Next does not in any way fix or solve the error. It simply instructs VBA to continue as if no error occurred.

 

On Error Goto <You’re Defined Label>: It tells VBA to transfer execution to the line following the specified line label. Whenever an error occurs, code execution immediately goes to the line following the line label.  None of the code between the error and the label is executed, including any loop control statements.

Example: Compile Time or Syntax Error

Sub Check_Error()

Dim name As String

name = “Rekha Mor”

MsgBox “Welcome ” & name ”

End Sub

15 thoughts on “Managing VBA Coding Errors

  1. Hi there, I do think your web site could possibly be having browser compatibility issues. Whenever I look at your web site in Safari, it looks fine however when opening in Internet Explorer, it’s got some overlapping issues. I simply wanted to provide you with a quick heads up! Besides that, fantastic blog!|

  2. Just want to say your article is as surprising. The clarity on your submit is simply spectacular and that i could suppose you are knowledgeable on this subject. Fine along with your permission allow me to grasp your RSS feed to stay up to date with forthcoming post. Thank you 1,000,000 and please continue the rewarding work.|

  3. Hello there! This post couldn’t be written any better! Reading this post reminds me of my previous room mate! He always kept chatting about this. I will forward this post to him. Pretty sure he will have a good read. Thanks for sharing!|

  4. Hi there! I could have sworn I’ve been to this blog before but after browsing through some of the articles I realized it’s new to me. Anyhow, I’m certainly pleased I stumbled upon it and I’ll be book-marking it and checking back frequently!|

  5. After going over a few of the articles on your web page, I truly appreciate your way of blogging. I book marked it to my bookmark website list and will be checking back soon. Please visit my website as well and tell me your opinion.|

  6. Hi there just wanted to give you a quick heads up and let you know a few of the images aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same outcome.|

  7. I’m really enjoying the theme/design of your site. Do you ever run into any internet browser compatibility issues? A few of my blog audience have complained about my blog not operating correctly in Explorer but looks great in Firefox. Do you have any recommendations to help fix this issue?|

Leave a Reply

Your email address will not be published.

Enjoy the tutorial? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+2k
Google+
http://hirdeshbhardwaj.com/2016/09/29/managing-vba-coding-errors
YouTube49
YouTube