Before we get right down to the nitty gritty, you need to know the different locations where yo might install a macro. You also need to be aware if what you need to make your macro work for you.
So, let’s start with what you need when creating a macro in Excel. Below is an example of what the start and end of every macro have.
Sub The_Name_of_The_Macro ()
The code for your macro should come next.
Every single macro in Excel must start with Sub and end with End Sub.
The name of your macro must have an opening and closing parentheses after it. You can name your macro anything you like but it should be intuitive and describe the macro function.
All of the actual code for your macro will come after the name of your macro and before End Sub.
Ok, so now let’s talk a little about a number of different locations where you can install your macro in Excel because you need to know this before you go about installing it.
You can install your macro in a Module, Worksheet or Workbook.
Now that you have the basic information, it is time to install your macro.
Follow the steps below to learn how:
- Copy for the code for your macro and be certain to include everything between Sub and End Sub.
- Open your Excel workbook.
- Click Alt + F11 to open VBA (Visual Basic Application).
- Determine where you would like to install your macro.
- Double-click the location where you want to install it.
- Look at the graphic depiction above and double-click Sheet1 if that is where you want to install your macro, double-click This Workbook if you want to install it there.
- If you need to install your macro in a Module, and do not already have a module visible, go to the Insert menu and click Module and it will then be added.
- Once a blank window has opened you are ready to set up your macro.
- Now go back and Double-click the location where you want to install your macro, past all the macro code and into the blank window.
- You are now ready to run your macro.
- Click Alt + F8 to view all macros in your workbook and run your macro.
Once you have installed your macro it should look something like this:
I hope this has been helpful to you. Macros can be a bit intimidating to the uninitiated and hopefully this information has helped to demystify the process.