• Articles
  • Tutorials
  • Interview Questions

Understanding Macros in Excel with Example

Have you ever questioned how to turbocharge your Excel experience? Enter the world of Macros if you are curious enough about automating repetitive tasks and streamlining your spreadsheet game. In this, we figure out the magic of Excel Macros—what they are and how they can change how you work. Let's understand Excel Macros together!

Macros play a crucial role in streamlining workflows, proving to be incredibly useful in today’s fast-paced environment. In this blog, we’ll explore why we need Macros in Excel and understand various methods for running Macros in Excel.

Table of Contents:

Want to learn Excel from the basic to expert level? Check out the Excel course provided by Intellipaat!

What is a Macro in Excel?

In Excel, a macro is a sequence of instructions or commands that automate repetitive tasks by recording a series of actions performed within the software. Essentially, it’s a way to simplify complex or routine operations. Macros can be created by using Visual Basic for Applications (VBA) or recording actions step-by-step within Excel. 

They allow users to automate tasks like formatting data, generating reports, or performing calculations, thereby enhancing efficiency and saving time by executing multiple actions with just a click of a button or a keyboard Excel shortcut.

Example – Let’s assume you have an Excel sheet with a bunch of sales data. Instead of manually adding up the sales numbers every time, you can create a macro that does it for you! You record yourself clicking through the cells to add the numbers once, and then, with that macro, you can repeat that action whenever you want—just by running the macro. It’s like having a little Excel robot that follows your steps automatically, making your job way easier and faster.

Intellipaat provides an Advanced Certification in Microsoft Excel. Enroll now to get a professional certificate!

Why Do We Need Macros in Excel?

Macros are essential tools for Excel users who frequently perform repetitive tasks. They offer several benefits, including:

  • Simplifying Complex Operations: Macros make complicated calculations or analyses with multiple steps easier. They turn intricate sequences of actions into one command, making difficult tasks easier to handle.
  • Enhancing Productivity: Macros, through task automation and error reduction, have the potential to greatly enhance your overall productivity.
  • Consistency: Macros play a pivotal role in maintaining uniformity across data formats, calculations, and reports. Therefore, it helps to enhance the accuracy and dependability of tasks, especially when dealing with large datasets or performing recurring operations.
  • Time-Saving: By automating processes, Macros saves significant time. Tasks that might take hours when done manually can be completed within seconds or minutes using a well-designed macro.
  • Personalizing the Functions: Macros empower the creation of personalized tools and functionalities that are finely refined to suit your exact specifications.

Get 100% Hike!

Master Most in Demand Skills Now !

Turn on the Developer Tab in Excel

Enabling the Developer tab in Excel expands the toolset available to users, offering a broad range of specialized functionalities. This includes the creation, customization, and utilization of Macros, forms, and other advanced features. Activating this tab essentially unlocks a suite of capabilities that go beyond the usual Excel environment.

Here is the step-by-step guide to enable the developer tab in Excel:

  • Step 1 – Open Microsoft Excel, and you’ll see a row of tabs across the top of the screen, including “Home,” “Insert,” “Page Layout,” and more. The Developer tab isn’t there by default, so you’ll need to turn it on.
  • Step 2 – Click on the “File” tab at the top left corner.
  • Step 3 – On the left side of the menu, scroll down to the bottom and choose “more,” where you’ll find the “Options” tab. Click on “Options” to proceed.
  • Step 4 – Within the Excel Options window that appears, find and click on “Customize Ribbon” on the left-hand side.
  • Step 5 – On the right-hand side, you’ll see a list of main tabs with checkboxes. Look for the “Developer” checkbox, and enable it  by ticking the box adjacent to “Developer.”
  • Step 6 – Click “ok” at the bottom to confirm, and once you’ve enabled the Developer tab, you’ll see it displayed alongside other tabs like “Home,” “Insert,” etc., at the top of the Excel window.

How to Record a Macro

Let’s explore the process of recording a macro through a straightforward example. Imagine that your manager provides you with an employee table each month and instructs you to highlight the columns where the salary exceeds $58,000. In this scenario, we will utilize Macros for this task:

  • Step 1 –  Click on the Developer tab on the Excel ribbon, and within this tab, select the option to Record Macro. This will open the “Record Macro” dialog box.
  • Step 2 – Provide your Macro with a clear name in the “Macro name” field. For instance, let’s name our macro “formatting_salary.” Make sure to avoid spaces or special characters in the macro name.
  • Step 3 – Assigning shortcut keys to Excel Macros enables swift execution. By assigning a specific key combination, like “F,” you can easily trigger the macro by pressing those keys. This step is optional.
  • Step 4 – Choose where you want to store the macro. You can store it in “This Workbook” (accessible only in the current workbook), “New Workbook” (accessible in any new workbook), or in “Personal Macro Workbook” (accessible in any workbook).
  • Step 5 – Adding a description to your macro can make it easier to understand its purpose or what it does. Let’s say we add a description like “This macro is designed to format the salary cell.” 
  • Step 6 – Once you’ve set up the details, click OK to start recording your actions.
  • Step 7 –  Excel is now recording every action you perform, so go ahead and carry out the tasks you want the Macro to automate. Now, head over to the “Home” tab.
  • Step 8 – Select the salary range and then use “Conditional Formatting” to format the salary according to specific conditions.
  • Step 9 –  Afterward, select “Highlight Cells Rules” and then opt for the “Greater Than” tab.
  • Step 10 – When you see the ‘Greater Than’ dialog box, in the first column, enter ‘$58,000’ to filter values greater than this amount. In the second column, select ‘Light Red’ to color-format these cells.
  • Step 11 – We’ve formatted our salary cells according to specific conditions, and these steps have been saved in a Macro.
  • Step 12 – After you’ve completed your actions, go back to the “Developer” tab and click on “Stop Recording”. Excel will stop recording your actions.

By doing this, we’ve effectively captured our actions in a macro, allowing us to easily repeat these tasks whenever needed.

Check out Intellipaat’s guide on MS Excel Interview Questions to crack good interviews for data analysis jobs.

How to Run the Macro in Excel

There are various methods to execute a recorded macro in Excel. Let’s explore each one using the example we previously recorded, called “Formatting_salary,” with our employee table:

From the Developer Tab

  • Step 1 – Make sure you’re on the workbook where the macro was recorded. Next, go to the “Developer” tab on the ribbon and click the “Macros” button. This action will open up the Macros dialog box for you.
  • Step 2 – Within the Macros dialog box, you’ll find a list displaying all the Macros available in your workbook. Simply pick out the specific one you wish to run. For instance, let’s select the “Formatting_salary” macro we previously made to format the salary column.
  • Step 3 – Once you’ve chosen the macro, simply click ‘Run.’ Doing so will activate the selected macro, formatting our salary cells based on the conditions specified within the macro.

Using a Keyboard Shortcut

  • Step 1 – Go to the “Developer” tab on the ribbon and click the “Macros” button. This action will open up the Macros dialog box for you.
  • Step 2 – After you’ve opened the Macros dialog box, you’ll see a list showing all the available Macros in your workbook. Simply select the one you want to assign a shortcut to by clicking on it.
  • Step 3 –  Click on “Options” and this will open up the Macro Options dialog box. 
  • Step 4 – If you’ve been following along with our blog, you might have previously assigned a shortcut key within the “Shortcut key” dialog box. If not, you can simply assign any key combination there. For instance, Ctrl + Shift + F could be a useful choice.
  • Step 5 – Confirm the keyboard shortcut assignment by clicking ‘OK’ in the Macro Options dialog box. Then, whenever you need to execute the macro using the shortcut key you’ve set earlier, just press the specific keys you designated (such as Ctrl + Shift + F).
  • Step 6 – Select the range of values where you’d like to apply the macro, then press the shortcut key. This will format the cells based on the conditions specified in the macro.

Including a Macro Button in the Quick Access Toolbar

Step 1 – Locate the Quick Access Toolbar (QAT) at the top left corner of the Excel window. Click on the small arrow pointing downward on the right-hand side of the QAT. From there, choose “More Commands” in the dropdown menu.

Step 2 – In the Excel Options dialog box, under “Choose commands from”, select “Macros”.

  • Step 3 – Choose the specific Macro you wish to add to the Quick Access Toolbar from the list provided. Then, simply click the “Add >>” button to place it in the list on the right side of the Quick Access Toolbar.
  • Step 4 – After choosing the Macro for your toolbar, you can rename its button by picking it from the list on the right and hitting “Modify.” When you’re happy with all your choices, just click “OK” to close the Excel Options dialog box.

Step 5 – Your macro button is now on the Quick Access Toolbar. To use it, just select the values you want to work with and click this button whenever you want to run the macro. Easy as that! 

How to Save a Macro with the Workbook

Saving a Macro within a workbook ensures the automation remains intact for the specific file. Thus, it signifies that the macro travels with the workbook, allowing anyone who opens it to access and use the automation without needing separate installation or setup.

Here are the simple steps to save a Macro within your workbook:

Step 1 – Click on File -> Save As to save the workbook.

Step 2 – Click on the “Save as” option in the left panel

Step 2 – Select where to store the file, give it a name, and under “Save as type”, opt for “Excel Macro-Enabled Workbook”. Finally, click “Save” to secure your workbook, ensuring the macro is retained within.

Learnings from This Macros in Excel Guide

This blog emphasizes the importance of Macros in modern professional life. Macros are an outstanding addition that automates repetitive tasks, which ultimately saves valuable time and effort. They can be used to streamline processes, improve efficiency, and reduce errors. Their significance extends to industries that are heavily reliant on data management, like finance, accounting, and manufacturing. They can also be used to automate tasks in everyday life, such as sending emails, formatting documents, and organizing files. As technology continues to evolve, Macros are likely to play an even more important role in our lives.

Course Schedule

Name Date Details
Data Scientist Course 20 Apr 2024(Sat-Sun) Weekend Batch
View Details
Data Scientist Course 27 Apr 2024(Sat-Sun) Weekend Batch
View Details
Data Scientist Course 04 May 2024(Sat-Sun) Weekend Batch
View Details

Executive-Post-Graduate-Certification-in-Data-Science-Artificial-Intelligence-IITR.png