top of page
  • Writer's pictureKalpesh Agrawal

VBA Types of Errors and Error handling

There are 3 types of errors in VBA.

  1. Syntax errors: These will work for only a single-line statement at a time

  2. Compilation errors: These will work for more than one line at a time.

  3. Run time errors: In these errors, you will not get an error message, it can only find out when you test again the code. Like, you type 3 in place of 5 or you put minus sign (-) in place of the plus (+) sign.

Error handling: In VBA, if there is only 1 letter mistake in a code line it will show an error and do not let you proceed with the further code.

You can see in the above image that the first line of code is executed and enter the number 10 into cell A1, but when you try to run the next line it shows an error because as per mathematical rule any number cannot be divided by 0.

Till when you don’t remove the error, you can’t go ahead.

If you are running 100 lines of code and if make a small mistake like this, your code does not work until you resolve the error.

To solve this problem, have a look at the code given below.

You can see that the line of code with the error did not execute and skipped by VBA because it contains an error.


Related Posts

See All
bottom of page