What is Macros?
A Macros is a piece of programming code that runs in excel environment, and it helps to automate routine tasks. In other words, a macro is a recording of your regular steps in excel, which you can replay using a single button.
Importance of Macros in Excel
You can import the data into the format and excel. Every day you will be required to perform the same ritual. It might become boring and uninteresting.
Macros solve such problems by automating these routine tasks. so you can use a macro to record the steps of
- Importing the data.
- And you are formatting it to meet your business reporting requirements.
Macros Basics
Macros are one of the developer features. But the tab for developers is not displayed in excel. So, you will need to present it via the customize report.
Macros are used to compromise your system by attackers. They are disabled in excel. If you want to run macros, then you will need to enable running macros and only run macros that you believe it comes from a trusted source.
If you want to save the macros, then you must protect your workbook in a macro-enabled format *.xlsm and the macro name should not contain any spaces.
How to Write Macros
Let’s see how to write a simple macro in a step by step manner such as:
Step 1: Go to the File → Options in excel.
Step 2: Click on the Customize Ribbon tab and select the Developer.
Step 3: Click on the OK button.
Step 4: Create a folder in drive E named tutoraspire.
Step 5: And paste the annual-enterprise-survey.csv file that you downloaded.
Step 6: The Developer tab appears in the menu bar.
Step 7: Click on the Developer bar.
Step 6: And click on the Record Macro.
Step 7: A dialog box will appear to you.
- Enter the macro name.
- Store macro is entered by default.
- Enter the description, as shown in the below screenshot.
- Click on the OK button.
Step 8: Click on the Data tab.
Step 9: And click on “from text” button.
Step 10: Then you will get the dialog window shown in the below screenshot.
- Go to the local drive where you stored the CSV file.
- Select that CSV file.
- Click on the Import button.
Step 11: After that, you will get the Text Import Wizard window.
- Click on the Delimited checkbox.
- Also, select my data has headers option.
- Click on the Next button.
Step 11: Select the Comma options as a delimiter and click on the Next button.
Step 12: Then,
- Select the General option.
- And click on the Finish button.
After completing above all steps, you will get your workbook shown in the below screenshot:
To finish the macro, click on the Stop Recording macro option as shown in the below screenshot.
Step 13: Click on the Macros button.
- Select that macro named importMacro1.
- Click on the Run button.