VBA Editor

What Is Excel VBA Editor?

VBA Editor is a platform in Excel to write and edit the Visual Basic for Applications (VBA) code. It is a window where we can see all the VBA codes, be it in MS Excel, MS Word, or MS PowerPoint.

By default, in Excel, it is under the Developer tab. If you are using it for the first time, you may not see the Developer tab in your Excel workbook.

VBA Editor Definition-1

By default, you don’t see the Developer tab.

VBA Editor - All tabs

We have to enable this manually to access the VBA editor window. Follow the steps listed below to enable the Developer tab.

Step 1: Open an Excel workbook from your computer.

Step 2: Click on the “File” tab at the ribbon.

VBA Editor - Step-2-1

Step 3: Click on More and then click on “Options”.

VBA Editor - Step-3

Step 4: This will open the “Excel Options” window. In this window, click on “Customize Ribbon.”

VBA Editor - Step-4

Step 5: On the right-hand side, under Main Tabs, check the “Developer” tab check box.

VBA Editor - Step-5

Step 6: Click on “OK.” It should enable the Developer tab on the ribbon, and we can see the tab now.

VBA Editor - Step-6
Key Takeaways
  • VBA Editor is a window to store all the VBA codes. It can be accessed from the Developer tab.
  • The macro recorder can be used to record all the actions that we do in Excel, and it will store this as a VBA code.
  • We can create macros by naming a macro using a sub-procedure.
  • ALT + F11 is the shortcut key to open the Visual Basic editor window.

How to Open Visual Basic Editor?

Basically, we can open the Visual Basic Editor window using the following three methods.

  • Using Developer Tab
  • Using Worksheet Tab
  • Using Shortcut Key

Let us show you in detail how to open the Visual Basic Editor window in each method now.

#1 – Using Developer Tab

After enabling the Developer tab, click on it from the ribbon.

VBA Editor - Using Developer Tab

Under the Developer tab, click on the “Visual Basic” option.

VBA Editor - VBA

As soon as we click on the “Visual Basic” option, it will open the following Visual Basic editor window. You can also open the Excel VBA editor dark mode through the Tools tab.

VBA Editor - Properties

#2 – Using Worksheet Tab

Within the worksheet, we can open the VB editor window. For that, right-click on any of the worksheets in the Excel workbook and then click on “View Code.”

VBA Editor - Worksheet Tab

#3 – Using Shortcut Key

The fastest way to open the Visual Basic Editor window is by using the shortcut key. The shortcut key to open the Excel VBA editor shortcut is ALT + F11.

Hold the ALT key and then press F11 to open the Visual Basic editor window.

Visual Basic Editor Window

The Visual Basic Editor window looks basic with the icons used to showcase the ribbon. The following is the look of the Visual Basic editor window.

VBA Editor-Visual Basic Editor Window-1
  1. Menu Bar: Like Excel, the Visual Basic Editor window also has a menu bar. Here, we can insert modules from the Insert menu, format codes, debug, run, and do many other things.
  2. Tool Bar: In the toolbar section, we have all the shortcuts to access some of the features like save, run, pause, copy, cut, paste, etc.
  3. Project Window: In this section, we can see all the workbooks that are opened on our computer, along with the worksheets in that workbook.

From this section, we can launch the properties window by pressing the F4 key. For example, select any of the worksheets from the project window section.

VBA Editor-Visual Basic Editor Window-2

Now press F4 key. It will open the following properties window of the selected worksheet.

VBA Editor-Visual Basic Editor Window-3

In the properties section, we can play around with the properties of the worksheet, like changing the name of the worksheet, visibility, which can be set to true or false, and many other things.

How to Use VBA Editor?

The best way to start using the VBA Editor is by recording a macro.

Record macro is a feature available to record all the actions that we do in an Excel workbook and store them in VBA language.

Let’s follow the steps to start the record macro feature.

  1. Open an Excel workbook and go to the “Developer” tab.

    VBA Editor-Step 1

  2. Under the “Developer” tab, click on the “Record Macro” option.

    VBA Editor-Step 2

  3. This will bring the below “Record Macro” screen, which asks us to give a name to the macro. Give a desired name (without space) under the “Macro Name:” section.

    VBA Editor-Step 3

  4. Click on “Ok.” Now, Visual Basic is recording all the actions that are done in the Excel workbook. We can see the status “Stop Recording” instead of “Record Macro” under the “Developer” tab.

    VBA Editor-Step 4

  5. Now, perform the first action by selecting the cell A1.

    VBA Editor-Step 5

  6. After selecting the cell A1, enter some value in it.

    VBA Editor-Step 6

  7. Hit the Enter key to finish typing. Stop the recording by clicking on “Stop Recording” under the “Developer” tab.

    VBA Editor-Step 7

  8. Now, to see the recorded code, we must go to the Visual Basic editor window. Press the shortcut key ALT + F11 key to go to the editor. We will see the following screen.

    VBA Editor-Step 8

  9. Expand the “Modules” by clicking on the plus (+) icon.

    VBA Editor-Step 9

  10. Double-click on the module name (Module 1), and it will open the code window to the right of the side.

    VBA Editor-Step 10

We can see the code that the macro recorder recorded while the recording was going on.

VBA Editor-Step 10(1)
  1. Head of a Macro: All the procedures start with the keyword “Sub,” followed by its unique name. Remember, while starting the recording, the name “Test” was given, and it has been recorded here as well.
  2. The Code: Whatever action is performed after we start recording is recorded as code here. The first action was selecting the cell A1; hence, it has recorded this action as “Range(“A1”).Select”.
    Then, we entered the value “Testing Recording” and it has recorded this action as below.
  3. ActiveCell.FormulaR1C1 = “Testing recording”

After entering the value, we hit enter, and subsequently, it selected cell A2. This action is recorded below.

“Range(“A2”).Select”.

In this way, we can make use of the Visual Basic Editor window to play around with the recorded codes, and we can start creating our sub-procedures from scratch here.

Examples of Excel VBA Editor

Example #1 – Adding Modules on Editor

When we record a macro, Excel automatically adds a module to store the code for the actions that we perform in the Excel Workbook. The code area is a code window where we write the VBA code.

However, when you open the VB editor for the first time without using the record macro option, we end up seeing the window below.

VBA Editor-Example 1

Now, we must add the module manually to start writing the code from scratch without the help of the macro recorder. Let’s follow the steps below.

Step 1: Go to the Insert tab.

VBA Editor-Example 1-Step 1

Step 2: Under the Insert tab, click on “Module.”

VBA Editor-Example 1-Step 2

Now, it inserts the module for us.

VBA Editor-Example 1-Step 2(1)

Double-click on Module 1, and it will open the code window to the right side.

VBA Editor-Example 1-Step 2(2)

Another way to insert the module is by right-clicking on the workbook or worksheet objects. You will see an “Insert” option.

VBA Editor-Example 1-Step 2(3)

Hover on the “Insert” option, and you will see the “Module” option.

VBA Editor Example-1-Step-2-4

Click on the “Module” option, and it will insert a new module.

VBA Editor-Example 1-Step 2(5)

Thus, we can insert multiple modules. In the code window, we write the code. For example, enter the keyword “Sub.”

VBA Editor-Example 1-Step 2(6)

After the keyword “Sub,” enter a macro name.

VBA Editor-Example 1-Step 2(7)

After the macro name, hit the enter key, and it will create the tail of the macro automatically.

VBA Editor-Example 1-Step 2(8)

Inside the sub-procedure, we can write a code. For example, to insert a value 123 in cell A1, we can write a code as shown in the image below.

VBA Editor-Example 1-Step 2(9)

Similarly, we can create multiple modules and write separate codes.

Example #2 – Working with Properties Window

Working with Properties takes you a long way in VBA coding. Let’s explore this in detail in this example. The Properties tab is available for objects of VBA, i.e., the worksheets in the workbook.

VBA Editor-Example 2

Select any of the worksheet objects and press the F4 key to access the properties window.

VBA Editor-Example 2(1)

Name Property: To change the name of the worksheet, we use the “(Name)” property. Let’s give a different name to the worksheet “Sheet2.”

VBA Editor-Example 2(2)

Let’s go back to the worksheet and see if the name is changed there as well.

VBA Editor-Example 2(3)

Even though we have changed the name, it remains the same in the worksheet. The reason for this, though, is that the property “(Name)” is used to change the name of the worksheet at the VBA level and not the worksheet level.

Hence, to change the name at the worksheet level, we must use the “Name” property instead of the “(Name)” property at the top of the list.

Example-2-4

Now, the name of the worksheet will be changed to “New Report.”

VBA Editor-Example 2(5)

Visible Property: Visible is nothing but the hide and unhide in worksheet level. By default, the visible property is set to -1 – xlSheetVisible.

Let’s change the property to 0 – xlSheetHidden.

VBA Editor-Example 2(6)

Now, we cannot see this worksheet.

VBA Editor-Example 2(7)

Thus, we can work with the properties of the worksheets to manipulate them.

Important Things to Note

  1. By default, the “Developer” tab is not enabled in Excel. It has to be enabled manually. 
  2. Once there is a VBA code in the Visual Basic Editor window, we must save the file in “Excel Macro-Enabled Workbook (*.xlsm).”
  3. F4 is the shortcut to launch the properties window in the Visual Basic editor window.

Frequently Asked Questions (FAQs)

1. What are breakpoints, and how do I use them in the VBA Editor?

Breakpoints are nothing but a stop point to block the execution of the code temporarily. By applying a breakpoint, we can abandon the execution of the code at a particular line. The breakpoints can be cleared when they are no longer needed.

2. How do I debug VBA code in the Editor?

We can debug the code using the following methods.
• Execute the code line by line by pressing the F8 key.
• Enable the Immediate window to see the result of each executed line.
• Use breakpoint to analyse the error. F9 is the shortcut key to apply the breakpoint.

3. What is the Object Browser in the VBA Editor, and how can it be helpful?

Object Browser is the feature to set or enable object references to external objects like MS Outlook, MS PowerPoint, MS Word, and etc.

4. How to show line numbers in Excel VBA editor?

Unfortunately we do not have line numbers to show serial number for each line of the code like we see in other programming languages.
However, the VBA editor displays the line number and column number of the cursor position within the code area at the standard toolbar.

VBA Editor Question 4

Download Template

This article must help us understand the VBA Editor formula and examples. You can download the template here to use it instantly.

Guide to VBA Editor in Excel & its meaning. Here we explain how to use the VBA Editor with its properties, adding module, examples & downloadable excel template. You can learn more from the following articles –

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *