Subscribe for Weekly Tutorials
BONUS: subscribe now to download our Top Tutorials Ebook!
What is a Macro in Excel?
This is the first step to learning about Macros for Excel and how to use them.
What is a Macro?
A macro is a small program that you make in Excel that automates tasks.
Basically, this "thing", the macro, can save you hours of time. You can create macros that do almost anything in Excel and even other Microsoft Office programs.
How can Macros Help Me?
Macros are useful when you want to automate a repetitive, tedious, or complex process.
For example, you can create a macro that searches through all of the data in an Excel Workbook, compiles the important information, and emails that information through Outlook, and you can do all of this with just the click of a button once you make the macro.
In a moment, we will create a simple macro together, but first let's talk about how they are made.
What is VBA?
Macros are made using VBA, which stands for Visual Basic for Applications.
Visual Basic is a programming language, and if you start learning it from a book, it can be terrifically annoying and confusing.
All you need to know is that VBA is the programming language that is used to create Macros. You DO NOT need to be a VBA expert to make macros; you just need to follow the tutorials here! :)
Your First Macro
Now that you know what a macro is, let's create a simple one so you can see just how easy it is.
- Open Excel and hit the keyboard shortcut Alt + F11 and this will take you to the VBA window for Excel. It should look something like this:
- Go to the Insert menu and then click Module:
You should now see a window like this: - In the window type Sub and then whatever name you want to give your macro and then an opening and closing parenthesis.
Hit Enter to go to the next line and End Sub should automatically appear, like this:
The space between these two lines is where the macro code, the VBA, will go. - Here, I will type a very simple line of code that will output a pop-up message box that will say HI!
Now, we have created a macro for Excel using VBA! - Hit Alt + F11 to go back to Excel and then hit Alt + F8. This window should appear:
- You can see the name of the macro that we just created, my_macro. In this window, you will be able to see all of the macros that you can access. Select the macro and hit the Run button.
You should see a window pop-up like this:
Hit OK and the window will close.
That's it!
We have successfully programmed and run a macro for Excel!
Notes
As you can see, the basics of creating a macro for Excel are pretty simple. It does get more complex than this, but that depends on what you want to do. The best thing about creating macros though, is that you don't have to be a master programmer or even learn a lot about VBA in order to make some very useful macros.
Basically, since you are just creating a little helper program for yourself in Excel, you only need to learn the code that will do what you need; you don't need to learn everything about VBA to make complex macros.
The tutorials here will focus on teaching you how to do things with your macros and not just about conceptual crap that you'll never use.
Keep reading to learn more! :)
Make sure to download the sample workbook attached to this tutorial if you want to see the macro that was created.