A macro is a sequence of instructions that automates some aspect of Excel so that you can work more efficiently and with fewer Errors. Macros are written in VBA, which stands for Visual Basic for Applications, is a programming language developed by Microsoft.
Sub: A sub is made up of one or more lines of code. When we “Run” the sub, VBA goes through all the lines of code and carries out the appropriate actions. A macro and a sub are essentially the same thing.
Module: A module is simply a container for our subs. A module contains subs which in turn contain lines of code. There is no limit(within reason) to the number of modules in a workbook or the number of subs in a module.
VBA Editor: This is where we write our code. Pressing Alt + F11 switches between Excel and the Visual Basic Editor. If the Visual Basic editor is not currently open then pressing Alt + F11 will automatically open it.
When we use the term Excel Macros we are referring to VBA. The term macro is essentially another name for a sub. Any time you see the terms Excel Macros or VBA just remember they are referring to the same thing.
In VBA we create lines of instructions for VBA to process. We place the lines of code in a sub. These subs are stored in modules.
We can place our subs in the module of the worksheet. However, we generally only place code for worksheet events here.
In VBA, we create new modules to hold most of our subs. So for our first activity let’s go ahead and create a new module.
What you will learn:
What VBA is and why it is so incredibly useful
What are Macros
Creating Macros using macro recorder
Creating macro manually from scratch
How to write VBA code and execute it in Excel
How to make your macros work with workbooks, worksheets and the data on them
How to find and eliminate errors in your programs and make your macros run
Automation using macros.
Analyse the macro from the Developer tab or the View tab.
Examine the VBA window and VBA components.
Distinguish between absolute and relative references.
How to save workbook with macros
Create a module
Create a sub
Understand the difference between a module and sub
Run the code in a sub