Open In App

How to Insert and Run VBA Code in Excel?

Last Updated : 13 Nov, 2022
Comments
Improve
Suggest changes
Like Article
Like
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.


Next Article
Article Tags :

Similar Reads