Install a Macro into an Excel Spreadsheet

Add to Favorites

This tip will show you how to copy an Excel Macro into your workbook or spreadsheet. You will learn the different locations that you might install the macro as well as what you need to make sure is included in the macro for it to work.

First - Every macro must start and end like the example below:

Sub The_Name_of_The_Macro()

The code for the macro goes here.

End Sub

Every macro in Excel must start with "Sub" and end with "End Sub." The name of the macro must have an open and closed parenthesis right after it. You can name the macro anything that you want but you should make it describe the function of the macro. All of the actuall code for the macro comes after the name of the macro and before "End Sub."

Second - There are a number of different places where you can install a macro in Excel and you need to know this before you install the macro. You can install a macro ino a Module, Worksheet, or Workbook - See Image Below.

Where to install the Macro

 

How to install the Macro into Excel - Steps

  1. Copy the code for the macro. Make sure to include the everything between the "Sub" and "End Sub."
  2. Opend the desired Excel workbook.
  3. Hit "Alt + F11" on the keyboard (this shortcut works for all versions of Excel).
  4. Determine where you need to install the macro.
  5. Double-click the location where you need to install the macro - it will look like the above image. So, double-click Sheet1 if you need to install the macro there, double-click ThisWorkbook if you need to instal the macro there. If you need to install the macro into a module, go to step 6, otherwise skip to step 7.
  6. If you need to install the macro in a module and don't already have a module visible, go to the Insert menu > then click Module. A module will then be added.
  7. Once a blank window has opened up you are ready to install the macro. If no window opened up, go back to step 5.
  8. Past all of the macro code into the blank window.
  9. Rename the macro if need be and then hit the keyboard shortcut "Alt + F11" to close the VBA window and go back to the spreadsheet.
  10. You are now ready to run the macro. Hit "Alt + F8" on the keyboard in order to view all macros in the workbook and also to run the macro.

This is what the macro should look like once installed:

VBA Window Macro in Excel



Similar Content on TeachExcel
List All Files from a Directory into Excel
: Get a list of all files from a directory into an Excel worksheet. This allows you to navig...
Countdown Timer in Excel
Tutorial: How to create a countdown timer in Excel. This allows you to display a timer in whatever c...
Format Cells as a Scientific Number in Excel Number Formatting
Macro: This free Excel macro formats selected cells in the Scientific number format in Excel. Thi...
Automatically Run a Macro at a Certain Time - i.e. Run a Macro at 4:30PM every day
Macro: Automatically run an Excel macro at a certain time. This allows you to not have to wo...
Run a Macro When a Specific Cell Changes in Excel
Tutorial: Run a macro in Excel when a specific cell is changed; this also covers when a cell within...
Create a Bar Chart With a Macro in Excel
Macro: Create a bar chart in Excel with this macro. You will be able to quickly and easily t...