I see users of Excel shy away from using the VBA by saying that they don’t know VBA. I am a user of VBA and not a developer. I get most of the codes I use from online sources and make minor tweaks and adopt them into my own financial models. if like my friend who didn’t want to use the UDF because he thinks he doesn’t know how to write a code under VBA, then I want to tell you not to be intimidated by any of these things or don’t be a perfectionist and say I don’t know how to write the code so I will not use it! 95% of things we are using on daily basis, we are ignorent on how they function including electricity. So, just get into it and learn by doing instead of studying.

If you are new to VBA, I want you to follow these steps and insert your first VBA code in your model.

Task: Let’s say you want to add a table of content in your financial model and because you are lazy and smart at the same time, you want to automate this task.

Step 1: If you have the developer tab in your Excel ribbon then go to step 2. If however, you don’t have it, then follow the below stapes:

  1. On the File tab, go to Options Customize Ribbon.

  2. Under Customize the Ribbon and under Main Tabs, select the Developer check box.

Step 2: Let’s find the code: So, go to google and search for “VBA code add table of content”. I am using the one from Microsoft community.

Copy to Clipboard

Step 3: Go to your Excel file and open the VBA editor.

  1. On the Developer tab, go to Visual Basic. 

  2. If you don’t see the Project Explorer window (something like the below), then you can activate it from the view tab.

Step 4: Now, on the project explorer, you see all the Excel file open. You want to insert the code in your workbook and not in the other workbooks.

  1. under your workbook you should see 2 folders. One  called Microsoft Excel Objects and another one called Modules. We want to add another module and insert the code.
  2. right click on the module and Insert/Module 

  1. You should have a blank window, just copy and paste the code from the website in the blank window and you are done.

  1. Close the VBA editor and run the macro

Step 4: don’t forget to mention the source where you’ve got the code from inside your VBA macro code.