Open In App

How to Record a Macro in Excel

Last Updated: 19 Sep, 2023

A

Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

Excel Macro is simply a record button that records a set of actions performed on Excel that can be run multiple times. For example, if you have to format some raw data on a weekly basis you can use a macro to record yourself formatting the data once and let Excel automate the task in the future. it’s used to help users save time and avoid performing redundant tasks.

HOW-TO-RECORD-MACRO-IN-MICROSOFT-EXCEL

What is a Macro in Excel

In simple words, a Macro is a snippet of VBA code that empowers you to execute a series of actions with a single command. Whether you’re generating this code using a macro recorder or crafting it manually, it all falls under the umbrella of macros.

How to Get the Excel Developer Tab Show Up in the Ribbon

The first step to record a macro is to get the Developer tab turned on. If you already see the Developer tab in the ribbon, then you can directly follow the steps to record a macro.

How to Enable the Developer Tab in Excel

In order to record a macro the Developer tab on the ribbon needs to be activated as it isn’t on by default within Microsoft Excel. The developer tab contains all the macro tools among various other features. 

How to Activate: To activate it click on the file tab> go to options>Customize Ribbon. Under Customize the Ribbon and under Main Tabs, select the Developer check box. (The developer tab stays on the ribbon unless checked off ).

DeveloperTabGfG

Developer Tab

How to Record a Macro in Excel

Step 1: Select Macro

Click on the view tab, select Macros(extreme right), and hit Record Macro.

Select-Macro

Select Record Macro

Step 2: Record Macro Dialog Box and click Ok

A Record Macro Excel dialog box pops up. The record macro dialog box has 4 sections to be filled:

1. Macro name: Give a name to your macro (avoid spaces and keep it short)

Shortcut Key: you can select any letter to create a shortcut key, be careful not to override an existing shortcut key. (you can press shift and any letter in the box to create a ctrl+shift+letter  key)

2. Store macro in select: This workbook to run it only in the current workbook, personal macro workbook so the macro can be used within any workbook on the computer that contains that personal macro workbook and new workbook to run it in a new workbook it creates at the time of recording.

3. Description: Here you can provide additional information about the macro(what it does) for the users or ourselves.

4. Click ok and Excel will start recording all of your actions.

Select-Option-in-Macro-Dialog-box

Enter the Macro name

Step 3: Stop Recording Macro

Once done, remember to hit the stop recording button in the lower-left corner of the worksheet or head over to view>Macros>stop recording.

Stop-Recording

Stop recording button bottom left corner

Stop-Recording-button

Select Stop-Recording Button

How Macro works in Excel

Now let’s venture into Excel’s Backend, where the magic of macros truly unfolds- the visual basic editor(VB Editor). This is where we’ll dissect what happened when we record a macro and translate it into VBA code.

What is Visual Basic Editor 

Excel has a tool called the Visual Basic Editor or VBA that makes note of all the actions you perform while recording a macro in the backend. When you record a macro inside Excel through the macro recorder all the code gets stored in a module. To see the code that Excel has written head to the Developer tab>code section>Visual Basic this opens up a separate window called the Visual Basic Application window along the left side of this window you will find the module under the Project Explorer(if you don’t see it click on View>Project Explorer) double click it and all the text is the code that excel generated while recording the macro.

vbaGfG

Virtual Basic editor

Alternatively, you can use the keyboard shortcut Alt + F11( holds the Alt key and press F11).

How VB Editors works in Windows

VBA-Window

VBA Window

Menu Bar: This is a ribbon of VBA. You can access the tools and options from here within the VB editor.

Toolbar: Resembling the Quick Access Toolbar, the toolbar offers handy shortcuts. You can even customize it to suit your needs.

Project Explorer Window: This consists of the list of all workbooks and objects within each workbook. For example, if your workbook has 3 worksheets, they’ll be visible here.

Code Window: This is where the VBA code is either recorded or written.

Properties Window: You can view and modify the properties of different objects.

When we recorded the macro- For ‘enter text’, the following is a set of actions that occurred in the VBA editor:

  • A new module was inserted.
  • A macro named “Enter text” was recorded, as per our specifications.
  • The code was penned within the code window of the module.
window-module-gfg

VBA Window Module

What is Absolute Recording and Relative Recording

A macro can be recorded in 2 ways namely Absolute and Relative recording. When you record a macro in Excel it is by default in the Absolute recording mode. In the absolute recording, the steps are performed exactly in the cells the steps were recorded in despite the active cell. In simple words, absolute recording restricts the location of steps. Relative recording executes the steps recorded in any part of the worksheet selected by the user as its relative to the starting location of the macros. Follow the steps to record a macro in Relative reference mode:

Step 1: Select a cell and Click on the Developer tab

Select the cell where you want to insert the macro and Select the developer tab.

Step 2: Select Relative Reference

In the code group, click on the ‘Use Relative Reference’ button. It will turn green, indicating that it’s turned on.

RelativerefrencesGfG

Select Relative Reference

Step 3: Click Record Macro

Click the Record Macro Button.

Record-Macro

Select Record Macro

Step 4: Enter name for your Macro

In the Record Macro Dialog box, enter a name for your macro.

Name-the-Macro

Name the Macro

Step 5 : Select This Workbook and press Ok

In the Store macro option, make sure ‘this workbook’ is selected.

Cons of Excel Macros

Macros have certain limitations pertaining to them and can be combated by writing the VBA code manually. Some of them are as follows

  • A macro doesn’t record what options you select within a dialog box.
  • If you need to make any decisions in your process (code), the macro recorder can’t help you make them. you can use the IF statement or other conditional statements.
  • The macro recorder can’t throw message boxes to prompt the user.

What is an Excel Macro-Enabled Workbook

There are some file extensions that do not store a macro hence you need to be careful about using a macro-enabled format to save your workbook or the macro won’t be saved. 

The default Excel format of the Excel workbook is .xlsx which does not support macros.  To store macros you save and open workbooks in a new macro-enabled workbook format .xlsm. this format is the same as .xlsx but with the capability to support Excel macros.

The Excel Binary Workbook(.xlsb) and Excel macro-enabled template(.xltm) are some more file extensions that support macros within them.

How to Save a Macro in Excel for all Workbooks

Step 1: Navigate to the File Tab and Select Save As

Click on the File tab and then choose Save As. The Save As dialog box appears.

Step 2: Enter the Name for the Workbook

Enter a name for the and select a location for your workbook.

SaveasGfG

Save your Macro

Step 3: Select the File Type

Click the Save as Type drop-down arrow. A list of file types appears.

Step 4: Click on Save

Select Excel Macro-Enabled Workbook. Click on Save.

macroenabled2

Save Macro

Some more real-time applications of macros can be used to record the creation of charts based on some data, filtering and sorting data, formatting data, or importing it.

How to View Macros in Excel

To examine and modify the code of an Excel macro, you can use the Visual Basic Editor. To access the Editor, either press Alt + F11 or click on the Visual Basic button found in the Developer tab.

Screenshot-(159)

The Visual Basic Editor features various windows, but we’ll concentrate on the two primary ones:

Project Explorer: This window displays a list of all currently open workbooks and their respective sheets. It also showcases modules, user forms, and class modules.

Code Window: The Code Window is where you can view, edit, and write VBA code for each object listed in the Project Explorer.

How to Run a Macro in Excel

We already know the basic method of How to Run a Macro using the Macro Dialog Box. But there are other methods also to run a macro in Excel as mentioned:

Run a Macro from the Ribbon( Developer Tab)

Open the workbook with Macro -> Open the Developer tab in the code group -> click Macros -> Now select the Macro you want to run -> press Run.

Using Keyboard Shortcut

Alt +F11 – This key combination will open the Macro Editor in Excel.

Alt +F8 – This key combination will open the Macro Dialog Box.

Ctrl +Shift + M– This key combination will create a new macro in Excel.

Assign the Macro to a Shape

Click on Insert tab in the Ribbon -> Click Shapes in the Illustrations Group -> Select any Shape ->Draw the Shape -> Right click on the shape and select Edit Text -> Type Run Macro -> Format the Text -> Right click on the Shape -> Select Assign Macro from frop down -> Select the Macro.

How to Record a Macro in Mac

Macros in Excel for Mac use VBA (Visual Basic for Applications) just like in Excel for Windows, so the recording process is quite similar.

Step 1: Launch Microsoft Excel on your Mac

Step 2: Enable the Developer Tab (if not already enabled)

Quick Tip: If you don’t see the Developer tab in Excel’s ribbon, you need to enable it first.

Go to Excel -> Preferences in the top menu.

In the Preferences window, click on “Ribbon & Toolbar.”

Check the box next to “Developer” and click “Save.”

Step 3: Open a Workbook

Open the workbook where you want to record the macro, or create a new one.

Step 4: Access the Developer Tab

Click on the “Developer” tab in the Excel ribbon. This tab should now be visible after enabling it in the previous step.

Step 5: Start Recording the Macro

In the Developer tab, click on the “Record Macro” button. This will open the “Record Macro” dialog box.

Step 6: Name Your Macro

In the “Macro name” field, give your macro a descriptive name. Avoid spaces or special characters in the name.

Step 7: Specify a Shortcut (Optional)

You can assign a keyboard shortcut to your macro if desired. This step is optional.

Step 8: Choose Where to Store the Macro

Select where you want to store the macro:

This Workbook: The macro will be available only in the current workbook.

New Workbook: The macro will be available in any new workbooks you create.

Personal Macro Workbook: The macro will be available in all workbooks you open.

Step 9: Click OK to Start Recording

After configuring the options, click the “OK” button to start recording your actions.

Step 10: Perform Your Actions

Excel will now record every action you perform, such as formatting cells, entering data, or any other task you want to automate.

Step 11: Stop Recording

When you’re done with the actions you want to record, return to the “Developer” tab, and click on the “Stop Recording” button.

Your macro is now recorded and ready for use. You can run it at any time by either using the keyboard shortcut you assigned (if any) or by going to the Developer tab and selecting “Macros,” then choosing your macro from the list and clicking “Run.”

Also Read

FAQs

What are Macros in Excel?

A macro is a snippet of VBA code that empowers you to execute a series of actions with a single command. Whether you’re generating this code using a macro recorder or crafting it manually, it all falls under the umbrella of macros.

How to save a workbook with macros?

To save a workbook with macros, follow the below steps:

Choose the “Excel macro- enabled workbook” format from the “save as type”: drop-down menu in the “Save As “dialog box.

Is it possible to edit the recorded macro code?

Yes, you can edit the recorded macro code in the VBA. This allows you to customize and optimize the code to suits your specific needs.



A

News
Improve
Discuss
Do you want to advertise with us?Click here to know more

Excel Personal Macro Workbook

article_img
When we create the macros for automation, they can be used for that particular workbook only. We cannot access them outside that workbook in others. Excel Personal Macro Workbook is a hidden workbook in your local system that pops up whenever you open the Excel application. It is a place where all the macros from any workbook can be stored and one can use the macros from here which are often required. How to create a personal macro workbook? Creating a personal macro workbook is similar to creating a macro in Excel. Let's discuss it in some simple steps : Click on the developer tab on the ribbon and then click on the Record Macro tool in the Code group.A new dialog box would open.In the option, "Store Macro In", choose Personal Macro Workbook. In this way, our macro would be stored in the personal macro workbook.After filling the dialog box, click OK.In the last, click on stop recording in the developer tab. This is how a personal macro workbook can be created. How to view, create, copy and edit macros in Personal Macro Workbook? All the options like view, create, copy and edit macros can be done from VBA(Visual Basic for Applications) Editor. Let's discuss it in some simple ste
Read More

How to Password Protect Your Excel Macro?

article_img
It is a best practice, to protect the Macro (VBA Code) from other users to edit or view. In this article, we explain to create a simple macro and protect the same "VBA Project" using a password in Excel from other users. Implementation: Follow the below steps to protect your excel macro with a password: Step 1: Open an excel file, to create a simple “hello world” macro. Step 2: Press Alt + F11 – to open Visual Basic Editor. Step 3: Click Insert >> Module, which will add a new module as in Img1. Img 1 Step 4: Type the below code in “code window”. Sub firstMacro() MsgBox "Hello World" End Sub Step 5: Right-click “VBAProject (Book1)” and then click “VBAProject Properties”. Step 6: GoTo Protection Tab >> Check “Lock project for viewing” and type your password in both Password and Confirm password input text boxes. Press “OK” Step 7: Save your Excel workbook as Excel Macro-Enabled Workbook (*.xlsm) and close Step 8: Now reopen your excel file. Press Alt+F8 – to open the Macro dialog box. Select the macro “firstMacro” and click “RUN”. Step 9: Our macro will pop up below the message box. Close or press OK to hide the message box Step 10: Press Alt + F11 – to open Visual Bas
Read More

Assigning Excel Macro to Objects

article_img
In Excel, a recorded macro can be assigned to different objects like a shape, graphic, or control note. Instead of running the macro from the required tool in ribbon, we can create these objects to run them easily. They get very handy when multiple macros are there. Individual objects can be created for different macros. In this article, let's discuss how can we assign macros to different objects : 1. Assigning Macro to a Shape It is one of the easiest ways to run a macro is to create any shape in the worksheet and use it for running the macro. The steps that need to be followed are: Click on the Insert Tab on the ribbon. Go to the Illustrations group and click on the Shapes icon. In the sheet, choose any shape we like and want it to be assigned as the macro. Click where you want to add the shape in the sheet and the shape will automatically get inserted. The shape can be resized or re-formatted accordingly to the way you want. Text can also be added in the shape. Then Right-Click on the shape and a dialog box would be opened. Then click on Assign Macro. After right-clicking on the shape, another dialog box of Macro would be opened. In the dialog box, select the macro from the lis
Read More

How to Enable & Run a Macro in Excel? 6 Ways

article_img
We can record a macro in Excel or write from scratch in VB Editor. Excel provides different options to run a macro. In this article, we explore four different approaches to running a macro in an Excel application. Even while executing an Excel macro is a straightforward process for seasoned users, it might not be clear to newbies. You will discover numerous ways to execute macros in this article, some of which may entirely alter the way you interact with Excel files. The below macro will write the text “Geeks for Geeks” in cell B5 Sub updateText() ActiveSheet.Range("B5").Value = "Geeks for Geeks" End Sub How to Run a Macro from Excel RibbonFollow the below steps to run a macro in the Macro dialogue box: Step 1. Go to View >> Macros >> View Macros – to pop-up Macro dialogue box [keyboard shortcut - Alt+F8]. Step 2. Select a Macro from the list (e.g. updateText) and Press “Run” Output: How to Run Macro from VBA EditorFollow the below steps to run a macro in VBE: Step 1. Open Excel Step 2. Go to Developer>> Visual Basic – to open VBA Editor [keyboard shortcut - Alt+F11] Step 3. Select anywhere in the macro code and click the “Run button” (Green Arrow) or Press F5 How
Read More

N

How to Create a Macro in Excel: Build, Run, and Use Macros Easily

article_img
How Do I Create a Macro in Excel- Quick StepsOpen MS Excel > Start Recording a MacroPerform the Actions You Want to Automate > Stop RecordingRun the MacroAre repetitive tasks consuming your time in Excel? With this Excel macros tutorial, you can learn how to create and use macros in Excel to automate tasks and improve efficiency. This guide will walk you through the essentials, from understanding what macros are to creating a macro button for quick access. Whether you're a beginner looking for a step-by-step guide to Excel macros or someone eager to explore advanced features, this article provides everything you need to make and run a macro with ease.How to Create a Macro in ExcelTable of ContentWhat is Macro in Excel Uses of Macros in ExcelHow to Create a Macro in ExcelHow to Run a Macro in ExcelHow to Create a Macro button in ExcelEasy Tips for Creating a Macro What is Macro in Excel An Excel Macros is a set of instructions that you can create to automate repetitive tasks. Think of it like a recorded script that performs actions such as formatting cells, entering data, or generating reports, all with just a single click. This helps save time and reduces the chance of errors
Read More

How to Run a Macro Automatically

article_img
To run a macro automatically when the workbook opens one must enable the developer's tools in Microsoft Excel. What is a Macro in Excel Macros allows automating repetitive tasks in Microsoft Excel. Some tasks need to be performed multiple times and repetition of all the actions would consume time. In such type of Scenarios, Macros helps in automating these tasks. How to Enable the Developer's ToolStep 1: Go to File > Options > Customize Ribbon Step 2: Then checkmark the Developer's tool option in the customize ribbon option. Now you can record Macro, run Macro and do everything that a developer can do. How to Run Macro Automatically when the workbook opensStep 1: Go to the developer's menu and then go to the visual basic Step 2: Go to ThisWorkbook Tab Step 3: Write down Private Sub Workbook_open() and hit enter. You will then see the below screen. You can write your code or basically whatever you want between this and it will automatically run every time the workbook is opened. Let us make a Welcome Message Box: Step 4: Save the workbook as Excel Macro-Enabled Workbook. Note: If you don't save it as an Excel macro-enabled workbook then it will not save the macros and it will
Read More

What Does the Number in the Addchart2 VBA Macro represent?

A chart or graph can be made in an Excel spreadsheet by using the AddChart2 VBA macro. The desired chart type or style is indicated by the number in the AddChart2 VBA macro. The AddChart2 function uses this number as an input parameter to identify the type of chart or style to be constructed. Each chart type is given a different number. If change the argument 2 value, an area chart is represented by the number 1, a line chart by the number 3, and a pie chart by the number 5, similarly, formatting of charts can also be done if change the argument 1 value, data labels are added on the chart, by the number 202, dashed formatted chart is developed by the number 203. You can design a chart that displays your data in the most useful way for your purposes by providing the correct chart type. Data types Before moving forward, we need to learn about the various numerical data types, such as integers, decimals, or floating-point numbers, that may be part of the macro. The numbers in Addchart2 can be of any of the below-mentioned data types, hence it is necessary to know about them. 1. Integer: Using this data format, entire values can be represented between -32,768 and 32,767. 2. Long: Th
Read More

Wall Street Record All-Time High Bonuses

Synopsis - Considerably, the bonus pool of the year 2020 had also shown a significant rise of 25% growth over the year 2019, which was historically significant amidst the pandemic-induced recession. The report also mentions that the securities industry is consistent in terms of making up one-fifth of private-sector wages in NYC while comprising up to 5% of employment in the private sector. The year 2021 has been very economical for Wall Street financiers as the data released by New York State Comptroller Thomas P. DiNapoli suggests. Reportedly, Wall Street has handed all-time high record bonuses. According to the report, Wall Street securities employees received $257,500 per worker in bonuses last year. The amount is said to be at an all-time high. It grew by 20%than the previous year. The paid estimated bonuses are yet higher than the city's recently released growth projection of 15.7%. Meanwhile, where the average bonus has grown by 20% and the entire bonus pool for New York City (NYC) securities industry workers grew by 21% to $45 billion in 2021 during the traditional December to March bonus season, which increased from $37.1 billion in 2020. Considerably, the bonus pool of the
Read More

How to Record Your Screen on an iPhone

article_img
Have you ever wished to record a video of your iPhone screen to highlight a fantastic app or a handy feature? So look no further! This step-by-step instruction will teach you how to record your iPhone screen. We have you covered whether you have the most recent iPhone model or an older model. Keep reading further to learn more about screen recording on iPhone. The procedures mentioned in the article are best suited for iPhone devices running iOS 11 and are more advanced. Some steps may alter if you have an older iPhone or a different iOS version. Before you begin, remember that screen recordings can quickly take up your iPhone storage, especially if they are extensive. Consider backing up your iPhone images or deleting the storage on your iPhone. How to Turn on Your iPhone's Screen Recording FeatureAll iPhones with iOS 11 or later may record screens. Check the Control Center for the screen record button before learning to screen record on an iPhone. If not, add it. Starting recording will be simple and faster. Step 1: Access the Control Center MenuSwipe your phone screen either upwards or downwards to open the Control Center menu. Screen Recording feature not Visible Step 2: Check
Read More

How to Record a Phone Call on iPhone

Recording a conversation offers advantages that go beyond the immediate interaction. The practice of capturing phone conversations serves various purposes, like preserving an interview for future reference or archiving a heartfelt exchange with a family member for later enjoyment. Nevertheless, it's essential to seek consent from your conversation partner before initiating the recording, as not everyone may feel at ease with the idea of being recorded. How to Record a Phone Call on iPhoneThere are many different methods to record a call on an iPhone, some of them are mentioned below: Method 1: iPhone Call Recorder: Voice Memos AppMethod 2: Other Call Recorder Apps for iPhoneTapeACallRev Voice RecorderCall Recorder LiteMethod 3: How to Record Calls on iPhone Without an AppHow To record an iPhone phone call using Voice MemosVoice Memos is a pre-installed app on both iPhone and iPad devices. While many individuals utilize it for recording various audio content, it also has the capability to capture phone conversations on your iPhone. This feature comes at no additional cost and doesn't require the installation of any external apps. Pros Cons No requirement for the installation of an e
Read More
three90RightbarBannerImg