The Wayback Machine - https://web.archive.org/web/20240204105231/https://www.geeksforgeeks.org/how-to-insert-and-run-vba-code-in-excel/
Open In App
Related Articles

How to Insert and Run VBA Code in Excel?

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

In Excel VBA stands for (Visual Basic for Application Code) where we can automate our task with help of codes and codes that will manipulate(like inserting, creating, or deleting a row, column, or graph) the data in a worksheet or workbook. With the help of VBA, we can also automate the task in excel to perform all these tasks we need to insert and run the VBA code properly which we will discuss in this article. 

Steps to Insert and Run VBA Code in Excel

To use the VBA code properly in Excel we need to change the default macro security settings of excel for that we need to follow further steps

Step 1: Click on the “File” menu at the left top of the excel tab. 

Clicking-file-menu

 

Step 2: Select “Options” to get the “Excel Options” window.

Selecting-options

 

Step 3: Select “Customized Ribbon” in the “Excel Options” Window and then select the “Developer” check box in the “Main Tabs”.

Go-to-customize-ribbon-option

 

Step 4: Then return to the main Excel window to select the “Developer” ribbon and then click on “Macro Security” in the “Code” group.

Selecting-developer-tab

 

Step 5: Click on “Macro Settings” to select “Disable all macros except digitally signed macros”.

Clicking-macro-settings

 

Now, to insert and run the VBA in Excel so that we can write codes we need to follow further steps:

Step 1: In the main Excel window press “Alt + F11” to open Visual Basic Editor

Opening-visual-basic-editor

 

Step 2: Select “Sheet1(Sheet1)” in the “Project – VBAProject” tab.

Selecting-project

 

Then we will get a terminal where we can write the following code,

Terminal-to-write-code

 

Step 4: After writing a piece of code according to the user’s need  we need to press “F5” to run the code and then click on “Run” in the “Macro” Tab

Running-code-in-macro-tab

 

Then, the output of the code will be seen in the Excel sheet.

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Looking for a place to share your ideas, learn, and connect? Our Community portal is just the spot! Come join us and see what all the buzz is about!


Last Updated : 13 Nov, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials