Excel VBA is a powerful tool which enables the automation of tasks in Excel. It can be used to automate many repetitive tasks along with more complex applications. This quick tip guide shows you how to open the Excel Visual Basic Editor (aka Excel VBA Editor) and get started with VBA programming in Excel. Having access to the VBA editor lets you write your own VBA code or review recorded macros. Read on to see How to Open and Start Using the MS Excel VBA Editor
Open Excel VBA Editor
To open Excel visual basic editor,
Click the visual basic button on the developer tab.
If the Developer tab is not present, go to File -> Options -> customize ribbon and tick Developer.
You can also open VBA in Excel using Alt + F11 keyboard shortcut.
What is the VBA Editor
Great, now you’re in the editor, what is it? Microsoft Excel’s Visual basic editor can be referred to as, VBA editor, VB editor and even VBE. It is all the same thing. It’s the place where you can create macros and write scripts in Excel VBA.
The most basic sections of the editor is the Project View in which you can see modules listed down the left hand side. Think of this like a folder for your macros. Modules contain the code that is required for your macros to work. Its beyond the scope of this article to go into how to split out your code into objects but modules gives the user a powerful tool to create efficient and well organized code.
To get started writing code you will need to create a new module. Add a new module in VBA editor by clicking on VBAProject(Book1), right click, Insert Model. Delete a module by simply right clicking, Remove Module. Excel will prompt you to confirm before deleting.
Record a Macro in Excel
Recording a macro in Excel is a great way to automate tasks as well as a great tool to help learn more VBA code. A common trick is to record a macro and then review the VBA code to see how it works. Now you know how to open the VBA editor in Excel you should be able to record a macro, open the editor and view the code. You’ll see the system generated VBA can be messy but it will give you the key snippets of code needed for the desired action. These can be things as simple as formatting, copying, pasting, deleting or selecting a sell. Alternatively, you could get quite advanced and carry out entire tasks before going into the Excel visual basic editor to review the code.
The world really is your oyster when you get started recording macros in excel. Top tip is to start with small steps. You can always bulk all your small macros into one at a later stage but when it comes to reviewing each step its useful to keep it separate, at least when you are first getting started.
Run a Macro in Excel VBA Editor
Once you have entered the VBA editor, created a module and written some code you will want to run the code.
To run VBA code in VBA editor simply click the Run Macro button which is shaped like a small green triangle on the toolbar. You can also Run Macro in Excel VBA editor by pressing F5 shortcut.
This is a very quick introduction to show you how to open VBA in excel, create a new module and also run your macro once written. To write some actual code, as we have suggested above, a great tip is to record macros and then go back and review the code in the MS Excel VBA editor. You’ll be surprised how messy the generated VBA can get but it will give you the key snippets of VBA code you need to get started with Excel VBA programming and is a great way of learning the syntax of VBA. Alternatively, Google is your best friend when it comes to writing macros. So what are you waiting for, press Alt + F11 in Excel and get coding in VBA!
What to do next? REad our quick Introduction to VBA for MS Excel