EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home VBA VBA Resources VBA Tips VBA Macros
 

VBA Macros

Manisha Sharma
Article byManisha Sharma
Madhuri Thakur
Reviewed byMadhuri Thakur

VBA Macros

Introduction to Excel VBA Macros

If you are a frequent Microsoft Excel user, you must have done some routine work, like inserting cells in excel, formatting the cells every time, inserting rows or columns, inserting numbers as per our requirements, etc. These tasks might consume a lot of your time on a day-to-day basis. Is there any way to reduce the time these tasks take every now and then? In short, is there any way to automate these tasks so that you don’t need to work on them every now and then? The answer is a big YES! It is absolutely possible to automate such tasks under Microsoft Excel with the help of Macros.

 

 

What is Macro?

Excel is a tool that has been developed and enhanced by the community so that it can be really very handy as well as simple to use. Macro is a small piece of programming code, the same as we have in traditional programming languages such as C, C++, C#, etc. which can be used in excel to automate some of the tasks. In Excel, we have a separate environment to work on Macros. It is called Visual Basics for Applications. Within this environment, you can write, store as well as run the piece of codes using which you can automate the day-to-day stuff.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

How to Enable Developer’s Tab?

Before being able to create, store and run a macro, you need to first enable Developer’s Tab. This tab contains several options associated with Macros such as recording a macro, stop recording a macro, etc. We will see step by step how to enable the developer’s tab in Excel to proceed further with creating a macro.

Step 1: Go to the File menu tab in the currently open Excel sheet.

VBA Macros Step 1

Step 2: In the File menu, click on Options situated at the last of the list of available options under the menu. It opens up a list of all options available under Microsoft Excel.

VBA Macros Step 2

Step 3: In a window opening up named Excel Options, click on Customize Ribbon to access the ribbon customization options.

Customize Ribbon

Step 4: Here in the customization options, you can see the Developer option. Checkmark it, so that it gets activated on the main ribbon of excel and can easily be accessed. Click OK after checking the Developer option.

VBA Macros Step 4

As soon as you hit OK, you can see the Developer tab active in the Excel ribbon menu with a bunch of different options available under. See the screenshot below.

VBA Macros Step 5

How to Record a VBA Macro?

Being a VBA automation expert, it all starts with recording a macro.

You can download this VBA Macros Excel Template here – VBA Macros Excel Template

We will now record a simple macro, a one in which you can input your name and navigate to the next cell all automatically. Pretty exciting, isn’t it? Follow the steps below.

Step 1: Navigate towards the Developer tab in your current working sheet which you just enabled.

Developer tab

You can see the whole bunch of options available under the Developer tab. As similarly as a real-life developer or automation expert has several automating options with him.

Step 2: Choose an option called Record Macro. It allows you to record whatever tasks you do on an active excel sheet and create a macro in the backend for the same so that you can automate the stuff.

Record Macro

Step 3: As soon as you click on the Record Macro button, you’ll be able to see a pop-up window where you can name the macro, can add a shortcut for it and can add a description for the same as well. I will change the name of the macro and add a shortcut for it. Hit OK after all the amendments.

VBA Macros Example 1-3

After you hit OK, your system starts to record the macro. Means, whatever tasks you are going to do in the excel sheet are being stored as a macro. You can see the Record Macro button has changed to Stop Recording. It means that the macro has started to record.

VBA Macros Example 1-4

Step 4: I will enter my name in cell A2 of the Excel sheet and hit the Enter button. After that, cell A3 will automatically be selected or we can say the editor moves towards cell A3. This is the task which we are automating. Click on the Stop Recording button after all these editions.

VBA Macros Example 1-5

Congratulations, our macro is created.

Step 5: Under the Developer tab click on the Visual Basic option to see the code we have created.

 Visual Basic option

You can see the code under the Module section in Visual Basic Editor pane.

Module section

Now we will check whether the macro we have created is working fine or not.

Step 6: Delete the data from cell A2. Click on the Macros button under Developer tab and run the macro.

VBA Macros Example 1-8

You can see that the name “Lalit Salunkhe” is inputted in cell A2 and cell A3 is selected next.

VBA Macros Example 1-9

This is how we can record a macro in excel. Don’t forget to save this file as a Macro enabled file so that all the macro’s get stored in the VBE.

Creating Squared Numbers using Macro

Follow the below steps to create squared numbers using macros in Excel VBA.

Step 1: Start Recording a macro. I gave a name to this macro as Squared_Numbers and used Ctrl + Shift + B as a shortcut for this macro. Click the OK button and the macro will start recording.

VBA Macros Example 2-1

Step 2: Now, in column A, input the numbers from 1 to 10 across the cells A2:A11. These are the numbers for which we would like to have squares in column B.

VBA Macros Example 2-2

Step 3: In cell B2, use the asterisk to multiply cell A2 by itself and hence creating a formula same as of squaring a number.

VBA Macros Example 2-3

Step 4: Drag the fields down until B11.

VBA Macros Example 2-4

Step 5: Click on the Stop Recording button to stop the recording.

Stop Recording button

Now, in order to test whether the code is working fine or not, delete all the data across columns A and B.

Step 6: Click on the Macros button and run the macro named Squared_Numbers.

Squared_Numbers

You can see the Numbers and Squares columns will get created respectively along with their column headers.

VBA Macros Example 2-7

This is how we can record and use a macro.

Things to Remember About VBA Macros

  • Always make sure you save the file as an Excel Macro-Enabled sheet so that the macro gets recorded in and can be used.
  • It is always a good practice to record a macro as it can be used for further automation irrespective of the workbooks.

Recommended Articles

This is a guide to VBA Macros. Here we discuss how to record macros in Excel and how to create a squared number using macros along with practical examples and downloadable excel template. You may also look at the following articles to learn more –

  1. VBA Web Scraping
  2. VBA CDate
  3. VBA Public Variable
  4. VBA Environ

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Web Development & many more.

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA

Download VBA Macros Excel Template

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW