VBA Excel

Microsoft VBA in Excel.

It helps you automate actions to be performed on worksheets.

VBA Excel

Microsoft VBA (Visual Basic for Applications) is a computer language based on Microsoft Visual Basic. In the Excel VBA context, it allows you to write code that automatically performs actions on a workbook, its worksheets and their columns, rows and individual cells. To write this code you can use a programming environment called Microsoft Visual Basic that ships with Microsoft Excel. This environment provides all the features you need to automate actions on a workbook.

To start writing VBA Excel, you will need to open the Microsoft VBA editor. Click the Developer tab > Visual Basic. If you can't see the Developer tab, click the Office Button > Excel Options, and check the Show Developer tab in the Ribbon option.

You will notice the following 3 main windows:

  • Project Window - shows a list of code segments available to your worksheet
  • Properties window - shows the characteristics of the selected object
  • Work Area - this is the area where your code is displyed

VBA Excel Modules

A module is simply a 'unit' of code. When you use VBA in Excel and work on a worksheet, a default module is automatically allocated for it. You can also create modules that are independent of worksheets. To create a module in the VBA Excel editor, click Insert > Module.

The Immediate Window

To enable you to test your code, Microsoft VBA provides a special window called the Immediate Window. To display the Immediate Window click View Immediate Window or press Ctrl-G. You can close this window at any time by clicking the 'X' in the top right.