HomeSoftwareMs ExcelHow to Create and Record a Macro in Microsoft Excel

How to Create and Record a Macro in Microsoft Excel

Creating a macro in Excel is an intelligent solution for automating repetitive tasks, significantly increasing work efficiency. This article guides you step by step, from activating the Developer feature to recording and running your first macro, complete with a practical example for automatic cell formatting.

Performing the same task repeatedly in Microsoft Excel can be time-consuming and error-prone. To overcome this, you can utilize the macro feature. An Excel macro acts as an action recorder. It records every mouse click and keystroke you perform. Subsequently, you can run that recording anytime to instantly repeat a series of commands. Thus, your productivity will increase rapidly.

However, the macro feature is not immediately visible on the Excel ribbon. Therefore, the first step is to activate the Developer tab. Furthermore, it is important to understand that macros are written in VBA (Visual Basic for Applications). Basic VBA knowledge allows you to edit and customize macros for more complex needs.

How to Activate the Developer Tab in Excel

The Developer tab contains all the tools for working with macros and VBA. This tab is hidden by default. Follow these steps to display it:

  1. Open the Microsoft Excel application.
  2. Click the File menu in the top left corner.
  3. Select Options from the list that appears.
  4. In the Excel Options window, choose Customize Ribbon.
  5. In the right panel (Customize the Ribbon), check the box next to Developer.
  6. Click OK to save the changes.
How to activate the Developer tab to create a macro in Excel
Steps to activate the Developer tab via Excel Options.

After that, the Developer tab will appear on the main Excel ribbon. This tab becomes the gateway to all automation functions, including creating a macro in Excel.

Steps to Record a Macro in Excel

Recording a macro is a simple process. You just need to perform the commands you want to automate. Excel will translate them into VBA code. Follow this guide:

  1. Open a workbook and select the cell or cell range you want to work on.
  2. Go to the Developer tab.
  3. Click the Record Macro button.
Record Macro button in the Excel Developer tab
The Record Macro button starts the action recording process.
  1. In the Record Macro dialog box, give your macro a name. Avoid spaces.
  2. Optionally, assign a Shortcut Key (e.g., Ctrl+Shift+M) to run the macro quickly. Ensure the shortcut does not conflict with Excel’s built-in commands.
  3. Choose where to store the macro, usually This Workbook.
  4. Click OK to start recording.
  5. Perform all the actions you want to automate (formatting cells, entering formulas, etc.).
  6. When finished, return to the Developer tab and click Stop Recording.
Stop Recording button to end Excel macro recording
Click Stop Recording after all actions are completed.

The recording process is now complete. You have successfully created a macro in Excel. The macro is ready to run anytime.

Practical Example: Create a Macro for Cell Formatting

Let’s create a concrete example. You will create a macro to instantly apply borders, change the font, and format numbers.

  1. Prepare a simple data table in a worksheet.
  2. Select the cell range to be formatted.
  3. Follow the macro recording steps above. Name it “BasicFormat”.
  4. After clicking OK, perform the following actions:
    • Go to the Home tab > Font group > select All Borders.
    • Change the Font Size to 11 and set it to Bold.
    • Number format: click the Number group > select Currency.
  5. Click Stop Recording.
Example result of cell formatting with an Excel macro
Cell comparison before and after running the formatting macro.

How to Run and Edit a Macro

To run the macro, select the target cells. Open the Developer tab, click Macros. Select the macro name (e.g., BasicFormat) and click Run. The selected cells will be instantly formatted.

If adjustments are needed, you can edit the VBA code. From the Macro window, select the macro and click Edit. You will enter the Visual Basic for Applications (VBA) Editor. Here, you can modify the code manually. Official Microsoft resources, such as the Excel VBA documentation, are very useful for learning more syntax.

Important Note: Files containing macros must be saved in the Excel Macro-Enabled Workbook (*.xlsm) format. If saved as *.xlsx, all macro code will be lost. Always pay attention to security warnings when opening macro-enabled files from unknown sources.

By mastering how to create a macro in Excel, you save time and reduce manual work. Start with simple, repetitive tasks. Next, explore VBA code to develop more sophisticated automation tailored to your specific workflow.

Latest Articles