How To Use The VBA Code You Find Online

So you needed to do something in Excel and after a bit of searching online, the solution you found involves some VBA code (visual basic for applications). If you’ve never used VBA and don’t know where to put the code and how to run it then follow this step by step guide to using the VBA code you found online.

Step 1: Enable the Developer tab in the Ribbon.

 

step-001-how-to-use-the-vba-code-you-find-online

 

By default the Developer tab is hidden and you will need to enable it to use in the ribbon.

  1. Go to the File tab.
  2. Click Options section.
  3. Click the Customize Ribbon section.
  4. Check the Developer box.
  5. Press the OK button.

 

Step 2: Open the visual basic editor.

 

step-002-how-to-use-the-vba-code-you-find-online

 

Now you should see the Developer tab in your Excel ribbon and you can open the visual basic editor (VBE) from the ribbon.

  1. Go to the Developer tab.
  2. Press the Visual Basic button in the code section.

 

Alternatively, you can open the VBE with the Alt + F11 shortcut.

 

Step 3: Insert a module into the current workbook.

 

step-003-how-to-use-the-vba-code-you-find-online

 

On the left hand side of the VBE you should see the Project Explorer side bar. This will list all your open workbooks and VBE objects associated with them. If you don’t see the project explorer, go to View > Project Explorer or press Ctrl + R.

  1. In the Project Explorer, find the workbook you want to use the VBA code in and right click on it.
  2. Click Insert from the menu.
  3. Click Module from the sub-menu.

 

step-004-how-to-use-the-vba-code-you-find-online

 

A new item will appear in the project explorer called Module1 and the previously grey space will contain a white section. This is the module code window.

  1. Click on Module1.
  2. Paste your code in the module.

 

Step 4: Run your code.

 

step-005-how-to-use-the-vba-code-you-find-online

 

Now you can run your code.

  1. Go to the Developer tab.
  2. Press the Macros button from the Code section.
  3. Select your code from the Macro window.
  4. Press the Run button

 

Alternatively, to open the Macro window you can use the Alt + F8 shortcut.

 

Note: For saving your workbook.

 

step-006-how-to-use-the-vba-code-you-find-online

 

You will need to save your workbook as a macro-enabled file type if you want to use this code the next time you open the workbook. These file types all support macros (VBA).

  1. Excel Macro-Enabled Workbook (*.xlsm)
  2. Excel Binary Workbook (*.xlsb)
  3. Excel 97-2003 Workbook (*.xls)

 

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and qualified actuary with over 15 years of experience. He has worked in a variety of industries, including insurance, ad tech, and most recently Power Platform consulting. He is a keen problem solver and has a passion for using technology to make businesses more efficient.

Subscribe

Subscribe for awesome Microsoft Excel videos 😃

John MacDougall

I’m John, and my goal is to help you Excel!

You’ll find a ton of awesome tips, tricks, tutorials, and templates here to help you save time and effort in your work.

Related Posts

Comments

0 Comments

Get the Latest Microsoft Excel Tips

Follow Us

Follow us to stay up to date with the latest in Microsoft Excel!

Subscribe for awesome Microsoft Excel videos 😃