Excel VBATutorial           

             

Excel VBA Macros

Email to excel-vba.com

Excel Tutorial on Macros

 Excel Consulting

Here is a sample of what you will find
in the downloadable 
Tutorial on Excel macros

Managing VBA Coding  Errors

The Visual Basic Editor will help you avoid errors in coding in many different ways. You will not have to wait at the end to be told that there is something wrong with your macro.


Spelling Errors

You have seen in lesson 11 the VBE capitalise letters to let you know that there are no spelling errors.


Syntax Errors

The VBE will also tell you that there is a syntax error in what you have just written by making the font red and showing you a message box.

Exercise 1

Step 1: Open a new workbook in Excel and use the ALT/F11 keys to go to the visual basic editor (VBE).

Step 2: In the code window of any of the sheet copy/paste the following line of code: Range(A1").Select and click "Enter".

You get the following message box telling you that you are missing a "list separator". Look for the error before the segment highlighted in blue. We can deduce that VBA is talking about the missing quotation mark.

VBA-syntax-error

Step 3: Click on the "OK" button.

Step 4: Add the missing quotation mark, use the mouse to move the cursor to the end of the sentence and click "Enter". The font is black meaning that everything is correct.

Exercise 2

Step 1: In the code window that you have used for exercise 1 copy/paste the following line of code:
Range("A1".Select
and click "Enter".

You get the following message box telling you that you are missing a "list separator". Look for the error before the segment highlighted in blue. We can deduce that VBE is talking about the missing parenthesis. Both the quotation marks in the exercise above and the parenthesis in this exercise are considered as "list separator" by the VBE.

Syntax error in VBA

Step 2: Click on the "OK" button.

Step 3: Add the missing parenthesis, use the mouse to move the cursor to the end of the sentence and click "Enter". The font is black meaning that everything is correct.

Step 4: Close Excel without saving anything


There are many other ways that the VBE uses to alert you to coding errors. You will learn about them all in the downloadable tutorial on Excel macros. You will also learn how to use "If" statement to catch errors during the execution and how to use the OnError statement to generate user friendly error messages like the following:

Error in VBA


We hope you have enjoyed this tip
For more on this topic and a complete course on Excel macros download the
Tutorial on Excel Macros


To organize your discovery of Excel macros, the downloadable Tutorial on Excel Macros is divided in three sections (all 3  sections part of the single download):

Section 1: Excel Macros Programming (Chapters 1 to 10)
This section is about recording, writing, modifying and testing macros in the Visual Basic Editor. You will also learn about security and discover "events" (an event is what starts the macro).

Section 2: Excel VBA Vocabulary (Chapters 11 to 23)
Developing a macro is communicating with Excel and to do so you need to use a language called Visual Basic for Applications (VBA). In section 2 you will learn all the VBA vocabulary that is essential to work with business data (accounting, sales, production and others).

Section 3: Forms and Controls in VBA for Exce (Chapters 24 to 33)
The userform is a small or large dialog window that you create and allows the user to submit values that will be used by your macros. To these userforms you will add controls (command buttons, text boxes, list boxes and others) and program them.