Automate Excel: Set Macros to Run Instantly

Victoria Jul 07, 2026

Automating repetitive tasks in Excel can save you time and reduce human error. One powerful way to do this is by setting up macros. A macro is a series of instructions that Excel can follow to perform a task automatically. In this guide, we'll walk you through the process of creating and setting up a macro to run automatically in Excel.

How to Create Macros in Excel Tutorial
How to Create Macros in Excel Tutorial

Before we dive in, ensure you're familiar with the basics of Excel macros and have the Developer tab enabled in your Excel ribbon. If not, you can enable it by right-clicking on the ribbon, selecting 'Customize the Ribbon', then checking the box next to 'Developer'.

How to Record a Macro in Excel - A Step by Step Guide
How to Record a Macro in Excel - A Step by Step Guide

Creating a Macro

Before a macro can run automatically, it needs to be created. Here's how:

5 macros I use to automate my Excel workbook
5 macros I use to automate my Excel workbook

1. Open the Developer tab and click on 'Visual Basic'. This will open the Visual Basic for Applications (VBA) editor.

2. In the VBA editor, go to 'Insert' > 'Module' to insert a new module. This is where you'll write your macro.

How to Create Excel Macros So You Can Work Faster (+ video tutorial)
How to Create Excel Macros So You Can Work Faster (+ video tutorial)

Recording a Macro

If you're not sure how to write a macro from scratch, you can record your actions in Excel and let the software create the code for you.

1. In the VBA editor, click on 'Developer' > 'Record Macro'.

a computer screen with the words use macro recorder in excel
a computer screen with the words use macro recorder in excel

2. Give your macro a name, choose a shortcut key if desired, and click 'OK'.

3. Perform the actions you want the macro to replicate in Excel. When you're done, click 'Stop Recording' in the 'Developer' tab.

Writing a Macro

Use This Trick to Automate Any Excel Task (Better Than Macros)
Use This Trick to Automate Any Excel Task (Better Than Macros)

If you prefer to write your macro code manually, you can do so in the module you inserted earlier.

Here's a simple example of a macro that displays a message box:

Clean Up Financial Duplicate Data with This FREE Excel Macro!
Clean Up Financial Duplicate Data with This FREE Excel Macro!
How to Run Macro in Excel
How to Run Macro in Excel
How to Edit a Macro in Excel - Tutorial
How to Edit a Macro in Excel - Tutorial
How to Enable Macros in Excel Without Risks
How to Enable Macros in Excel Without Risks
how to add macro to the quick access toolbar ribbon in excel for beginners
how to add macro to the quick access toolbar ribbon in excel for beginners
Insert Numbers Using Macros | MyExcelOnline
Insert Numbers Using Macros | MyExcelOnline
5 Cool Microsoft Excel Macros for Sorting Data
5 Cool Microsoft Excel Macros for Sorting Data
Macros in Excel with VBA code examples - MacrosInExcel.com
Macros in Excel with VBA code examples - MacrosInExcel.com
How to Write a Simple Macro in Microsoft Excel
How to Write a Simple Macro in Microsoft Excel
How to Enable Macros in Excel Without Risks
How to Enable Macros in Excel Without Risks
Learn Excel MACROS in 10 Minutes Using Real World Examples
Learn Excel MACROS in 10 Minutes Using Real World Examples
Save Macros In Active Workbook To Clean Up Financial Databases
Save Macros In Active Workbook To Clean Up Financial Databases
Quickly Hide Subtotals In Financial Pivot Tables Using Excel Macro Buttons
Quickly Hide Subtotals In Financial Pivot Tables Using Excel Macro Buttons
the text autofit rows using macros in excel
the text autofit rows using macros in excel
How to Create & Use Excel Macros (Real world example)
How to Create & Use Excel Macros (Real world example)
Excel Simplified- Recording Macro in 4 Easy steps [With Live Example] | IT4nextgen
Excel Simplified- Recording Macro in 4 Easy steps [With Live Example] | IT4nextgen
Excel Tutorial to Sort Data Automatically without using Macros
Excel Tutorial to Sort Data Automatically without using Macros
Learn Excel Macros with This Practical Example!
Learn Excel Macros with This Practical Example!
[LEARN NOW] 101 Ready to Use Macros in Excel
[LEARN NOW] 101 Ready to Use Macros in Excel
Easy Simple Smart
Easy Simple Smart

```vba Sub MyMacro() MsgBox "Hello, this is my macro!" End Sub ```

To run this macro, press 'Alt + F8' in Excel, select 'MyMacro', and click 'Run'.

Setting Up a Macro to Run Automatically

Now that you have a macro, let's set it up to run automatically when you open a workbook or perform another action.

1. In the VBA editor, go to 'Tools' > 'Options'.

2. In the 'Options' dialog box, select the 'Events' tab.

Running a Macro When Opening a Workbook

To run a macro automatically when you open a workbook, follow these steps:

1. In the 'Events' list, select 'Workbook'.

2. In the 'Macro' column, select the macro you want to run.

3. Click 'OK' to close the dialog box. Now, your macro will run automatically every time you open the workbook.

Running a Macro with a Keyboard Shortcut

If you want to run a macro with a keyboard shortcut, follow these steps:

1. In the 'Events' list, select 'Application'.

2. In the 'Macro' column, select the macro you want to run.

3. In the 'Macro' column, click in the cell where you want to set the shortcut key and press the key you want to use.

4. Click 'OK' to close the dialog box. Now, you can run your macro using the keyboard shortcut you set.

Remember, macros can be powerful tools, but they can also cause problems if not used carefully. Always make sure you understand what a macro does before running it, and be cautious when enabling macros from unknown sources.

Now that you know how to set up a macro to run automatically in Excel, you can start automating your most repetitive tasks and saving time. Happy automating!