
In case of WrittenMacro itĭeliminates the programming code you want to execute when running the WrittenMacro routine: anything written between The VBA editor immediately created the “End Sub” line when you hit enter. In this case type “sub WrittenMacro” and hit enter. To start a new subprocedure type “sub” (anywhere below Option Explicit) followed by a space and the name of the How to use functions is discussed in Chapter 7. The subprocedure which we will see first. When writing a macro the main basis will be The type of code that executes an action is a “Subprocedure”, whileĪ “Function” returns a value (like the functions in the Excel worksheet). Generally the objective of a group of code isĮither to execute an action or to return a value. In the module you have to write the programming within different groups of code. “Tools -> Options -> Editor” (on Mac: “Excel -> Preferences. If you want Option Explicit automatically in your newly created modules (recommended), then go in the VBA editor to Or, if you didn’t want to use a reserved keyword, it indicates you would need to use other words. So in case you wanted to use a reserved keyword the colour and capitalising let you know “reserved keyword” means that Option Explicit is something that has a predefined function in Excel VBA and can onlyīe used for the predefined purpose. Of each reserved keyword should automatically turn to a capital letter if you initially typed all in lower case letters. All reserved keywords recognised by the editor turn blue. It turns blue (may be rather dark color of blue). If Option Explicit doesn't show up automatically at the top of your new module then you can type it yourself on the first line of the empty sheet. Misspell the name of a variable (more about variables later in this chapter). This is good programming practice as it prevents possible mistakes in your macros, for example if you inadvertenty Writing Option Explicit at the top of a module means you have to define (“declare”) all variables used Option Explicit is a module-level statement, which means it holds for all the programming you do in this module. Figure 1: VBA editing window on Mac in Office 365 If you have any issue accessing the VBA editing window then have a look at the Preparations section If so, you can close that module‘s window, we will The VBAĮditing window shows empty, or as below with a module open from FUNCRES.XLAM. You can go to the “Developer” ribbon and choose “Visual Basic”. Open a new Excel workbook and access the VBA editing window by pressing Alt+F11 on a Windows computer or Option+F11 on Mac. Common errors when compiling or executing.In this chapter we will discuss the following Excel VBA elements: Through Chapter 1: How to record a macro. It is useful, but not indispensible to first have gone In this chapter we will see how to write a macro from scratch. Excel VBA Tutorial Chapter 2: How to write a macro Goal of this chapter
