Visual Basic Applications (VBA) and Macros in Excel

By Indeed Editorial Team

Published April 26, 2022

The Indeed Editorial Team comprises a diverse and talented team of writers, researchers and subject matter experts equipped with Indeed's data and insights to deliver useful tips to help guide your career journey.

Microsoft Excel is a powerful tool for organizing, displaying, and working with different types of data. Visual basic applications (VBA) is a programming language you can use to deploy powerful scripts, called macros, that can automate Excel tasks and extend the functionality of the program. Learning about VBA and macros can help you understand the uses of these complex tools and start automating work in Excel. In this article, we explain what VBA and macros are, discuss the advantages of using them, provide basic instructions for getting started, and give tips for using these tools.

What are VBA and macros in Excel?

VBA and macros in Excel are tools that extend the functionality of Microsoft Excel and allow the user to write custom programs or use generated scripts to automate tasks, connect different applications, and tackle problems in a different way. VBA is the programming language used to create and deploy macros. This language allows you to write code that can perform the same functions you have access to in Excel and customize and automate certain features and tasks. It gives you more control to complete tasks exactly the way you want.

Macros, written in VBA, are scripts or sections of code you can use to perform specific functions or automate tasks. You can find pre-made Macros within Excel, or you can instruct the program to record your actions and automatically create a macro. Any code you write in VBA that performs a function in Excel is a macro. To use macros, you can adjust your Excel security settings and enter a specific area of the program.

Advantages of using VBA and macros

There are several advantages to using VBA and macros over the traditional point and click functionality of Excel. Here are some of the main benefits of using these tools:

Save time

VBA and macros allow you to save time by automating repetitive tasks. If you try to point and click through changes to large documents or multiple files, it can be time-consuming. Creating a macro that automatically completes the same task can save you a substantial amount of time, especially when you're dealing with large amounts of data. This allows you to focus on other aspects of your project. Creating a macro may take time and effort, but it can result in a streamlined work experience.

Related: Advanced Excel Skills: Definitions and Examples

Reduce errors

When you make changes to an Excel file manually, you can introduce errors if you don't pay careful attention. The more changes you make and the faster you try to work, the more errors you are likely to make. When you create a macro and deploy it within Excel, it can complete the work for you without making a mistake as long as the program is correct. Once you have a macro set up and running, it guarantees the same result every time, significantly reducing the chance of errors in your work.

Related: A List of Intermediate Skills in Excel to Include in Your Resume

Extend functionality

VBA and macros allow you to make changes to the way other users can interact with the document you create. You can extend the functionality of your document by adding prompts, custom commands, and instructions that appear when the user takes a certain action. This can be important when you're working on documents with multiple people. You can use VBA and macros to guide the user experience and make your files more user friendly.


You can use VBA and macros to connect your work in Excel with other Microsoft programs, such as Word and PowerPoint. This can be useful for taking data from Excel and creating a PowerPoint presentation or including information from a Word document in a spreadsheet. You can control all these Microsoft applications using the VBA language and take advantage of their different features.

Related: How to List Microsoft Office Skills on a Resume

Getting started with VBA and macros

VBA, like any programming language, can be challenging to learn at first. Read the instructions carefully and use internet searches to learn more about anything you're unsure about. Here are some steps for getting started with VBA and macros:

1. Change the security settings

The default setting for Excel has macros switched off to protect you from accidentally running malicious code. To run your own macros, you can change the security settings in Excel. Once you have Excel running, click on "File," followed by "Options." Within Options, click on "Trust Centre" then click on "Trust Centre Settings." Then, click on "Macro Settings," and choose a new security setting. Some of the security settings allow you to run all macros without restriction, while others allow you to control which macros run by clicking on a prompt each time.

2. Enable the Developer tab

The Developer tab is where you can find the VBA settings. It's usually off by default. To enable the Developer tab, go to the File tab and choose "Options". Then, choose "Customize Ribbon," look under the Main Tabs drop down list, and check the box that says "Developer." After clicking the "OK" button, the Developer tab appears at the top of the Excel window.

5. Open the Visual Basic Editor (VBE)

Once you have the Developer tab enabled, you can access the VBE. Here, you can write and edit VBA code. First click "Developer," followed by "Visual Basic." There are different sections within the VBE. The project window on the upper left of your screen shows items that can contain VBA code. On the upper right, you see the code window, where you can enter the new code in the VBA language.

6. Record a macro

When you record a macro, you automatically generate code based on the actions you take within a document. To start recording a macro, click on the Developer tab followed by "Record Macro." Accept the settings, write a name for the macro you plan to create, and choose "This Workbook" as the location. Then, click "OK" to start recording.

Any action you take within the document is now recorded in VBA code. Click on "Stop Recording" to finish recording the macro. To view your new macro, click on the Developer tab, followed by "Macros," and choose the name of your macro. Then, click "Edit" to view the code.

Tips for using VBA and macros

Learning to use VBA and macros can make difficult tasks easier and help you automate aspects of your work. Here are some tips for using VBA and macros more effectively:

Start slowly

If you're unfamiliar with basic coding principles, VBA code can look intimidating. Start slowly, and learn basic coding principles before you try to automate tasks within your own Excel files. Try to work through basic tasks using macros and take the time to read each line of code carefully. Once you learn the basic functions of VBA, you can start to automate complex tasks. Coding languages generally have a strong internal logic and consistency, so once you master the terms and parameters, you can start to work with confidence.

Use internet searches

Use internet searches to help you find the solutions to complex problems within Excel. There are many websites that provide examples of VBA code for you to copy and use for your own work. When you search for a solution, try to be as specific as you can about what you are seeking. Try using different search terms if you struggle to find appropriate code. Programmers often share coding solutions online and build on each other's work, so don't be afraid to search for help.

Try multiple methods

Problem solving within Microsoft Excel requires patience and a willingness to try different approaches. When you encounter a problem or task you want to complete, think about different ways you can approach it and decide which might be more efficient. Sometimes, it's faster to complete Excel tasks by hand rather than by using macros. If you choose to use macros and automate a solution, there are also many problem-solving methods to choose from. You can write your own script in VBA, record macros to automate tasks, or copy code from other programmers.

Take a course

If you want to learn VBA quickly and thoroughly, consider taking a course. There are many courses on VBA offered online, and they can walk you through how to get started with programming and solve common problems in Office by using macros. Taking a course in VBA and macros can also help you gain important credentials for advancing in your career.

Please note that none of the companies, institutions, or organizations mentioned in this article are affiliated with Indeed.

Explore more articles