if you define an array indexed from 1 to 10, then attempt to access entry no. Subscript out of range(this error arises if you attempt to access elements of an array outside of the defined array size - e.g. However, some of the more common VBA error messages are shown in the table below: 5 The different runtime error codes are explained on the Microsoft Support Website. This can be done in the VBA editor by simply hovering your mouse cursor over the variable name, or by opening the local variables window (by selecting View→Local s Window).
#Visual basic editor excel 2016 compile error syntax error code#
If your code is more complex, you can gain further information on the reason for the VBA error by looking at the values of the variables in use. In the above example, the information provided in the message box, and the highlighted line of code, make it very easy to spot the cause of the error. In this case, clicking on the Debug button on the debug message box, causes the line of code that generated the VBA error to be highlighted in your vba editor. This type of VBA error is also usually relatively easy to fix, as you will be given details of the nature of the error, and shown the location where the code has stopped running.įor example, if your code attempts to divide by zero, you will be presented with a message box, which states "Run-time error '11': Division by zero".ĭepending on the structure of your VBA project, you may be given the option to debug the code, (see below). Runtime errors occur during the execution of your code, and cause the code to stop running.