Coding: Getting started in VBA

January 29, 2011
By

Some of you might be very familiar with VBA, and others might not be familiar with it or might have never even heard of it.  I wrote this quick tutorial for the people that fall into the latter two categories, so I will make it as easy as possible with only a few lines of code.  I am going to use Excel for this tutorial, so let’s get started:

1.       Launch Excel and select the “Developer” tab, if you do not see the tab then do the following:

  • Click on the Office button and select “Excel Options” and then check the “Show Developer tab in the ribbon” check box.

2.       Once you selected the “Developer” tab, click on “Visual Basic”.

3.       A new window will open up (“Microsoft Visual Basic”), there you will click “Insert” and select “Module”.

4.       Type the following code (told you I will make it simple):

Sub firstTutorial()

MsgBox “Hello World!”

End Sub

  • Just an FYI, once you finish the first line, the “End Sub” will automatically be added.

5.       Press F5 to execute your code, and you are done!

6.       Save the worksheet as an Excel Macro-Enabled Workbook.

I hope I made this tutorial as simple as possible for the readers that never did anything with VBA before.