Excel offers the feature of recording macros to computerize recurring tasks. Macros are a set of commands compiled together in the form of a code that can run recorded instructions to automate a task. You can use Macros when you repeat the same set of functions on Excel. Running macros saves time in tasks that generally take some time.
If you often find yourself repeating the same set of tasks, consider creating macros in Excel. In this article, we will be delving into the steps you could follow to create a macro in Excel, so keep reading!
How to Create a Macro in Excel?
Excel records your mouse clicks and keystrokes to create a macro which is then stored as a code in the Visual Basics Language. Creating a macro can be a bit tricky if you’re not used to the programming language. However, you could go through the process of trial and error to create the macro.
Step 1: Enable Developer Tab
You can only create a Macro in the Developer tab. By default, the Developer tab is hidden from the menu bar. You can, however, customize your menu bar to display the developer tab. Your first step towards creating a macro is to enable the developer tab from Excel Options.
Refer to the following steps to enable the Developer Tab on the menu bar of your Excel program:
- Launch MS Excel.
- From the sidebar, select Options. If you do not see it, head to More > Options.
- Select Customize Ribbon from the panel to your left.
- Choose Main Tabs under Customize the ribbon.
- Select the box next to Developer.
- Click OK.
Step 2: Record a Macro
Now that you have enabled the Developer tab on the menu bar, you can head to the tab to record your macro. As we mentioned, when you record your macro, Excel registers your keystrokes and compiles them as a singular command. So, while recording them, remember to carry on with your actions exactly how you wish to replicate.
Here are the steps you can follow in recording a macro on MS Excel:
- Open the MS Excel application to open a workbook.
- Head to the Developer Tab.
- Select Record Macro from the Code section.
- In the Record Macro window, enter the following details:
- Macro name: Give your Macro a name to uniquely identify it.
- Shortcut key: Enter a shortcut that will call the Macro in the Excel workbook. Remember not to use an existing shortcut, as Excel will override that command to run the Macro.
- Store macro in: Choose where you want the recorded macro to work in.
- Description: If you want to jot down any comments about the macro, enter them in this section.
- Carry on with the action you wish to record as a macro.
- After you’re done, select Stop recording on the Developer ribbon.
Step 3: Edit Your Macro
After you’re done recording your Macro, you may want to tweak a few things in the code. You could’ve accidentally entered a command you would not wish to replicate while the macro is automating your tasks.
As we’ve mentioned prior to this, a macro is stored as a code in the Visual Basic programming language. Hence, you need to understand the language before attempting to make any changes in the code.
Follow these steps to edit your macro from the Visual Basic Editor:
- Select the Developer tab.
- Choose Macros from the code section.
- Choose your Macro, then select Edit.
- View the Visual Basic Code and make the necessary changes.
- Run the macro, then see if it works as you like.
How to Run a Macro in MS Excel?
You can run a macro you’ve created in Excel from the Developer tab. If you do not have the Developer tab enabled, head to Excel Options to turn on the display for this tab. Once you’ve enabled the tab, follow these steps to run your Macro in MS Excel:
- Open your Excel file.
- Select the Developer tab from the menu bar.
- Choose Macros from the ribbon in the Code group.
- Select the Macro you wish to run under Macro name.
- Click on the Run button.
How to Delete a Macro in MS Excel?
If you no longer need to use a Macro, you can quickly delete it. It is a good idea to get rid of Macros you don’t use, as they usually take up space and increase the size of your workbook.
If you wish to delete a Macro in MS Excel, follow these steps:
- Open your Excel workbook.
- Select the Developer tab.
- Click Macros from the Code section.
- Select your Macro from the box, then select the Delete button.