What is a Macro in Excel?

Add to Favorites
Author: don | Edits: don

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.

  1. 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:
    e3f591c2da637d46aef68a36b7c9bd88.jpg
  2. Go to the Insert menu and then click Module:
    5e056d339fea72b0bb5b5e4f4a42a003.jpg
    You should now see a window like this:
    b607e0050019332cbec343681b770b80.jpg
  3. In the window type Sub and then whatever name you want to give your macro and then an opening and closing parenthesis.
    ade5d1ac26216e74cd79a084dfc33541.jpg
    Hit Enter to go to the next line and End Sub should automatically appear, like this:
    a90eb4a1b002f40ea6d9befbefc33399.jpg
    The space between these two lines is where the macro code, the VBA, will go.
  4. Here, I will type a very simple line of code that will output a pop-up message box that will say HI!
    80a7c8a479729bef1863d76a34c75f34.jpg
    Now, we have created a macro for Excel using VBA!
  5. Hit Alt + F11 to go back to Excel and then hit Alt + F8. This window should appear:
    da1d0837041ae5cccb658993b99b98b9.png
  6. 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:
    66faf93edf259a396f63b55adda51011.jpg
    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.

Question? Ask it in our Excel Forum


Downloadable Files: Excel File

Similar Content on TeachExcel
Get Data from the Worksheet into a Macro in Excel
Tutorial: Here, you'll learn how to get information from the Excel worksheet into a macro so you can...
Put Data into a Worksheet using a Macro in Excel
Tutorial: How to input data into cells in a worksheet from a macro. Once you have data in your macro...
What is a UserForm in Excel?
Tutorial: A UserForm is basically a pop-up window that you can use to create a custom interface for ...
Do Something Every so Many Rows with a Macro in Excel
Tutorial: How to have a macro do something on a set interval of rows; for instance, input a value ev...
Dates in Excel Explained
Tutorial: I'll explain how dates in Excel work and then point you to many useful tutorials on how t...
Install a Macro into an Excel Spreadsheet
Tutorial: This tip will show you how to copy an Excel Macro into your workbook or spreadsheet. You w...
Tutorial Details
Downloadable Files: Excel File
Similar Content
Get Data from the Worksheet into a Macro in Excel
Tutorial: Here, you'll learn how to get information from the Excel worksheet into a macro so you can...
Put Data into a Worksheet using a Macro in Excel
Tutorial: How to input data into cells in a worksheet from a macro. Once you have data in your macro...
What is a UserForm in Excel?
Tutorial: A UserForm is basically a pop-up window that you can use to create a custom interface for ...
Excel Forum