Get a month of TabletWise Pro for free! Click here to redeem

Different Types of Errors in action

3 minutes
Share the link to this page
You need to purchase the class to view this lesson.
One-time Purchase
List Price:  $139.99
You save:  $40
List Price:  د.إ514.18
You save:  د.إ146.92
List Price:  A$200.99
You save:  A$57.43
List Price:  ৳11,866.71
You save:  ৳3,390.73
List Price:  CA$190.20
You save:  CA$54.34
CHF 94.14
List Price:  CHF 131.80
You save:  CHF 37.66
List Price:  kr923.82
You save:  kr263.96
List Price:  €123.99
You save:  €35.42
List Price:  £111.45
You save:  £31.84
List Price:  HK$1,084.93
You save:  HK$310
List Price:  ₹10,477.20
You save:  ₹2,993.70
List Price:  RM598.38
You save:  RM170.98
List Price:  ₦54,246.12
You save:  ₦15,500
List Price:  kr1,324.07
You save:  kr378.33
List Price:  NZ$213.40
You save:  NZ$60.97
List Price:  ₱6,939.32
You save:  ₱1,982.80
List Price:  ₨23,350.33
You save:  ₨6,672
List Price:  S$195.06
You save:  S$55.73
List Price:  ฿4,367.55
You save:  ฿1,247.96
List Price:  ₺959.76
You save:  ₺274.23
List Price:  R2,396.08
You save:  R684.64
Already have an account? Log In


Alright guys, so let's have some examples for the different types of errors that we might encounter in Excel VBA. So if you right workbooks, my workbook, and then I missed the second double quote here and close the brackets dot open, you can see here we got a compiler. But before we even got the message box for the compiler, you can see here that our code turned red. So this is a syntax error. Your code turning red means you have a syntax error, you have a grammar or spelling mistake. So our grammar or spelling mistake here is that we didn't put the second double quote.

So this is a syntax error. Now to have an example for a compiler. Let's say we put instead of workbooks, we put just the word workbook here. Now, this is still not generated this syntax error because the word workbook is a word that is part of the Excel VBA dictionary. So VBA recognizes this word as part of its dictionary. And so it will not tell you there's a spelling mistake.

However, when it tries to run the code, it will generate a compiler because although the word workbook exists in the VBA dictionary, it is not put in the right context, it's it does not make sense to put it in this context. So if you run the code here, you'll get a compile error because the word workbook cannot be used in this context. So you need to use workbooks, not workbook. So this is a compiler. Now to have an example, for a runtime error, if we write worksheets, my worksheet dot select, as you can see here, our code has not turned red. So that means that there isn't a syntax error.

And also, we can check for a compile error. And we can do that even before running our code by going to the Debug menu here and clicking on compile VBA project. So if you click on that, And we don't get an error. That means that there aren't any compile errors on our code. And if we run this code, though, we will get an error. And the reason for that is that although this action is a valid action to select a worksheet called my worksheet, we will not be able to do it.

Because we do not have a worksheet that is called my worksheet in this current workbook. So if you run that, you will get an error subscript out of range. And that is because we do not have a worksheet in this workbook that is called my worksheet that we can select. So this is about action. However, we cannot do it because there isn't a worksheet that is called my worksheet that exists. Now the errors that you're going to be dealing with the most or that you're going to be encountering the most are actually runtime errors.

Because syntax errors are going to be pretty obvious when you write your code you will have it highlighted in red indicating the part of your code that is having a problem and you Most of the time, you'll be able to figure out what the problem is. and compile errors as well are going to get you an error on that part of the code. And actually, your code will not start running in the first place. So be able to discover it pretty early. Over runtime errors can happen actually, after the code runs for some time. And even after you try the code several times, where on some trials, your code runs fine, and on others, your code would generate an error.

So this is actually the error type that you're gonna be spending most of your time focusing on and handling, which is the runtime errors. So on the upcoming videos, we're going to be focusing on how to handle runtime errors. We're going to see different methods and techniques to do that. So thank you for watching this video and I'll see you on the next one.

Sign Up