Macros are a set of programming commands written in VBA that automate a repeated and standard process in Excel and other Microsoft Office Applications such as Access, PowerPoint, Word, and Outlook. Through the use of macros, we can automate repetitive tasks associated with data manipulation and data reporting that must be performed repeatedly.
Important of Macros in Excel
If you spend all day creating reports in Microsoft Excel, you know the power of this program; however, if you haven’t yet used macros, you don’t know half of it.
Macros simplify the repetitive keystrokes that you use in Excel to create and edit spreadsheets, which speeds up your production and reduces the time you have to spend staring at an electronic spreadsheet every day by reducing the number of keystrokes required to complete common commands.
Macros Basics
A macro is a set of commands and functions stored in a Microsoft Visual Basic module that can be run whenever you need to perform the task associated with the command. Macros are available for use in Microsoft Word, PowerPoint, and Excel.
If you wish to run macros, you must enable macros and only run macros that you believe to be from a reliable source. Macros have many benefits for those who use them. They eliminate the risk of human error that increases with repetitive keystrokes and tasks.
How to Write Macros?
Below are the steps on how to write macros on your devices:
Step 1: Open the Excel file for which you want to enable macros.
Step 2: Navigate to Customize Ribbon tab and the Developer checkbox by the left side of the window.
Step 3: Click on the OK button.
Step 4: Create a Excel Workbook in a drive “D” or any other drive and save it with name “xyz” or whatever name you want.
Step 5: Open the file which you created or if it is already opened then no need to re-open it.
Step 6: The Developer Tab will appear in the menu bar.
Step 7: Click on the Developer bar at the top of the window.
Step 8: Click on the Record Macro.
Step 9: The Record Macro dialogue box will appear on the screen. Give your macro a name and assign the shortcut which will activate the macro then click the OK button.
Step 10: Click on the Cell A1. Type here “This is my first macro”.
Step 11: Click on the “Home” and fill the yellow color in cell A1.
After completing above the steps, you will get your output in the workbook as shown in the below screenshot:
To finish the macro, click on the Stop Recording macro option as shown in the below screenshot.
Step 12: Click on the Developer >> Visual Basic >> Module1 then another window will appear. You will find the recoreded macro script in the module.
Step 13: Save the file with extention “Excel Macro-Enabled Workbook (.xlsm)“ or “Excel Binary Workbook (.xlsb)“.
Step 14: Click on the Macros button then another window will appear. Select that macro name Macro1and click on the Run button.